开发者

<%= link_to_function "Back", "history.back()" %> does not work in new and edit.html.erb

<%= link_to_function "Back", "history.back()" %>

The above does not work in new and edit.html.erb. The back link points to itself (/new# or /edit#) so it does not really go anywhere back. However the back button works in index.html.erb开发者_开发问答.

See another stackoverflow post on back button: 'Back' browser action in Ruby on Rails

Any thoughts? Thanks.

PS: Category controller:

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


A 'Back' link that satisfies most Rails applications' needs is to use the link_to helper:

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

The :back Symbol option is even noted in the Rails API docs.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜