I’m working with Ruby on rails 2.3.8 and the idea is to implement a “Sort” functionality for search results.
I’ve got the view(this is a part of it):
<span>Sort by:</span> <%= link_to 'MORE RELEVANT', search_filter_relevance_path %>
Routes file:
map.search_filter_relevance "/anuncios/search_filter_relevance", :controller => 'announcements', :action => 'search_filter_relevance'
and the controller’s action(doing nothing so far):
def search_filter_relevance
raise params.inspect
end
As its a search of announcements, I’d like to pass the collection of its results to the controller’s action so it filters them, and not all the announcements.
How can I do that?
Your question is kind of incomplete. It would have been great if you could provide the details of the entire controller code. Still i will try answering it.
A better approach would be to pass the “search term” itself. Say the search term was stored in an instance variable
@search.Your link_to should be:
<%= link_to 'MORE RELEVANT', search_filter_relevance_path(:search => @search) %>And your route should be:
map.search_filter_relevance "/anuncios/search_filter_relevance/:search", :controller => 'announcements', :action => 'search_filter_relevance'and your action: