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

时间:2011-09-29 22:33:59

标签: ruby-on-rails

<%= 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

1 个答案:

答案 0 :(得分:11)

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

<%= link_to "Back", :back %>

:back符号选项甚至在Rails API docs中注明。