<%= link_to_function "Back", "history.back()" %>
上述功能在new和edit.html.erb中不起作用。后面的链接指向它自己(/ new#或/ edit#)所以它实际上并没有回到任何地方。但是后退按钮适用于index.html.erb。
在后退按钮上查看另一个stackoverflow帖子: 'Back' browser action in Ruby on Rails
有什么想法?感谢。
PS:类别控制器:
class CategoriesController < ApplicationController
before_filter :require_signin
before_filter :require_employee
def index
if session[:eng_dh]
@categories = Category.all
else
@categories = Category.active_cate.all
end
end
def new
@category = Category.new
end
def create
if session[:eng_dh]
#dynamic attr_accessible
@category = Category.new(params[:category], :as => :roles_new)
if @category.save
#@categories = Category.all
redirect_to categories_path, :notice => 'Category was successfully created.'
# send out email
#NotifyMailer.new_prod_email(@product).deliver
else
render :action => "new"
end
end
end
def edit
@category = Category.find(params[:id])
end
def update
@category = Category.find(params[:id])
#@category.reload. caused nil.reload error
if @category.update_attributes(params[:category], :as => :roles_update)
#@category = Category.find(params[:id])
redirect_to categories_path, :notice => 'Category was successfully updated'
else
@categories = Category.all
render 'index'
end
end
def show
@category = Category.find[params[:id]]
end
end
答案 0 :(得分:11)