How implement the Back Link to the page from which comes from

天大地大妈咪最大 提交于 2019-12-25 01:43:06

问题


I have an application with associations and will pagination the pages.

The index page from the main object "cat_list" shows links to the association "data_lists". The index page has also pagination with "will_paginate"

  1. I show for example page=3 "/cat_lists?page=3"
  2. I click the link of a "data_lists" for example "/cat_lists/8984/data_lists"

This index page shows a list of data_lists with Edit, Destroy and a New link. And a Back Link to the cat_lists index page now "/cat_lists"

What is the best practice to implement the features, that the Back Link now the page from which comes from?


回答1:


I usually record the history in the session and then call it via redirect_to back (no colon)

def index
  ... do your stuff ...
  record_history
end

protected

  def record_history
    session[:history] ||= []
    session[:history].push request.url
    session[:history] = session[:history].last(10) # limit the size to 10
  end

  def back
    session[:history].pop
  end

Note that this only works for GET requests.




回答2:


If I understand you correctly link_to('Back', :back) is what you want.




回答3:


I also use mosch's approach.

link_to('Back', :back) only uses the browsers 'back' functionality. Managing the history server side gives you more control (i.e. if you've come from a google search, guess what happens on :back). Managing the history server side gives you the possibility to hide links that would take the user off your page. Further you can offer the user to browse multiple steps back - i.e. via dropdown.



来源:https://stackoverflow.com/questions/9840161/how-implement-the-back-link-to-the-page-from-which-comes-from

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!