'Back' browser action in Ruby on Rails

前端 未结 10 950
无人共我
无人共我 2020-12-23 13:24

Can the \'Back\' browser functionality be invoked from a Rails \'Back\' link?

10条回答
  •  伪装坚强ぢ
    2020-12-23 13:44

    If you like me do not want the behaviour of link_to "cancel", :back you could implement a helper method which either links to the records index path or show path. (i.e teams_path or team_path(@team)

    module CancelFormButtonHelper
      def cancel_button(record)
        index_path = record.class.to_s.pluralize.downcase + "_path"
        path = record.persisted? ? record : eval(index_path)
    
        link_to "Cancel", path
      end
    end
    

    which can then be used as <%= cancel_button @team %> within a form for example.

提交回复
热议问题