Reputation: 1393
My rails app has a basic search function that queries the database and displays a list of active records. The search results are displayed as links. When the user clicks on a link for a given search result they will be taken to a page with details of their selection and what not. I want to have a back button on this details page that will take the user back to the search results page with the search results still showing up. The way it is now the back button takes the user back to the search results page but all of the search results are gone.
Upvotes: 0
Views: 638
Reputation: 16513
Capture search query information in params[:query] and take it from one page to another.
In result detail page add this:
<%= link_to 'Back', "#{:back}+#{params[:query]}", :class => 'button' %>
Upvotes: 1
Reputation: 5914
You have to pass the query parameter(search text) to the details page where you have the back button.
Include the query parameter in the back button url as http://localhost:3000/search?query=foo
Upvotes: 1