'Back' browser action in Ruby on Rails

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

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

相关标签:
10条回答
  • 2020-12-23 13:48

    This will work similarly as browser back button try this

    <%= link_to 'Back', 'javascript:history.go(-1);' %>

    0 讨论(0)
  • 2020-12-23 13:51

    Use

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

    This is specificied in the RDoc here

    This generates some Javascript to navigate backward. I've just tested it, and it works.

    0 讨论(0)
  • 2020-12-23 13:58

    Pay attention to this comment from the user rthbound! As he notes, link_to with the symbol :back does not always generate a “real” back event as if the user clicked on their browser’s Back button. It can also be a resubmit of the action that loaded the current view.

    The documentation for Rails 4.2.6 says this about link_to and the :back symbol:

    Using a :back Symbol instead of an options hash will generate a link to the referrer (a JavaScript back link will be used in place of a referrer if none exists).

    0 讨论(0)
  • 2020-12-23 14:00

    Using

    link_to_function "Back", "history.back()"
    

    seems to be exactly like hitting the back button in the browser. All inputted form data is still there when you get back.

    0 讨论(0)
提交回复
热议问题