Bryan Cosgrove
Bryan Cosgrove

Reputation: 1393

Rails, link to previous page without losing content

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

Answers (2)

Syed
Syed

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

nkm
nkm

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

Related Questions