<%= link_to_function"返回","history.back()"%>在new和edit.html.erb中不起作用

use*_*363 3 ruby-on-rails

<%= link_to_function "Back", "history.back()" %>
Run Code Online (Sandbox Code Playgroud)

以上内容在new和edit.html.erb中不起作用.后面的链接指向它自己(/ new#或/ edit#)所以它实际上并没有回到任何地方.但是后退按钮在index.html.erb中有效.

查看后退按钮上的另一个stackoverflow帖子: 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
Run Code Online (Sandbox Code Playgroud)

sea*_*cal 11

满足大多数Rails应用程序需求的"后退"链接是使用link_to帮助程序:

<%= link_to "Back", :back %>
Run Code Online (Sandbox Code Playgroud)

:back符号选项,即使是在注意Rails的API文档.