Rails - saving search query / result

I have a search page that finds candidates. On this page, you can view the click to find additional information about the candidate. When on the candidateโ€™s submission you can click โ€œChangeโ€ or perform a number of other actions that will also return the candidates submission to you.

My problem is with the submission of candidates. I need to add a button to return to the search results. I initially thought about using a JS button with a history of -1, but since the user can perform other actions from within the view, this will not work.

Iโ€™m still completely new to rails, so Iโ€™m not sure of my capabilities ... I think this is some kind of caching of results, and then maybe a hidden field to track the location of the cache (do not think that this is the best solution, since tracking hidden value may become unavailable!)

Thanks, Alex

+3
source share
5 answers

I would probably use a session variable to store this information.

First, make sure that your form on the search page is a GET operation, so that the search data is in the query string. Then in your search action, you can grab the request URL and save it in the session:

session[:search_results] = request.url

, , " " :

link_to "Back to search results", session[:search_results]
+10

. : /foo/search?q=stuff . /foo/:id?q=stuff. .

- , -. , , , , .., , . , , .

+2

:

, . , , , . ( ).

, , . , .

!

+2

"search_results" . , , .

+1

- , , ( , Chrome Chrome), : .....

<%= link_to(image_tag("back.svg"), :back, :class => 'back_btn') %>
0

Source: https://habr.com/ru/post/1756617/


All Articles