How to program a Sort feature
I'm working on Ruby on rails 2.3.4 and I'm trying to develop a Sort feature on my website's search page(its url is /anuncios/buscar).
What I tried is to create a "map" on routes file:
map.search_filter_relevance "/anuncios/buscar", :controller => 'announcements', :action => 'search_filter_relevance'
Then, I wrote this on the view:
<%= link_to 'MÁS RELEVANTES', search_filter_relevance_path(@announcements) %>
And finally, I created a method in the controller, as is specified on the routes' line:
def search_filer_relevance
raise params.inspect
end
First of all, as I'm sorting search results, I'd like to keep them in their public variable called @announcements. Please help me do this.
An the other thing is that when I click the link I get an error due its trying to access the Show action instead of search_filter_relevance as specified in routes. Why is this happening?
EDIT:
It seems that I have a conflict between some of my lines at routes.rb file.
There more than one line that calls the same path. For example:
map.search "/anuncios/buscar", :controller => 'announcement开发者_如何学Gos', :action => 'search'
map.power_search "/anuncios/buscar", :controller => 'announcements', :action => 'power_search'
map.search_filter_relevance "/anuncios/buscar", :controller => 'announcements', :action => 'search_filter_relevance'
So if I click the Sort link I'll be redirected to the Search action instead of the 'search_filter_relevance'. But, if I change its path to another thing(for example: "anuncios/buscar_2") it will execute the action I want but it will ask me to create a template "buscar_2" for that, and I don't want to do this.
I just want to have a link button that when is clicked a table is sorted. That's all.
Any ideas?
The error is because the route helper method is search_filter_relevance_path
.
You can run rake routes
to see all of the routes and methods you have set up.
As for the sorting, searchlogic already exists, so I'd have to have a really good reason to reinvent the wheel.
精彩评论