问题描述:

I have a basic search page that replaces html in a div with the search results.

Clicking on one of the search results brings up a detail page. And I have a link on that detail page that says "Go back to search results".

My problem is that it just generates a link to the root_url. Is there a way I can generate a valid back link to those AJAX search results?

网友答案:

Using the example of an employee index, you can store the last search in your session, like so:

def index
  if params[:search]
    session[:last_search] = params[:search]
    @employees = Employee.search(params[:search])
  elsif session[:last_search]
    @employees = Employee.search(sessions[:last_search])
  else
    @employees = Employee.all
  end
end

Substitute whatever searching method you're using, of course. And there are a lot of ways this will look different depending on what else you're doing. But this should show you how to use the session hash to your advantage.

相关阅读:
Top