views:

57

answers:

1

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&Aacute;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 => 'announcements', :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?

+1  A: 

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.

jdl
Replacing "_url" with "_path" does not solve the issue. It keeps asking for Show action.
Brian Roisentul
BTW: seachlogic is really good. Thanks for the info.
Brian Roisentul
Did you post the wrong code? The example you have above doesn't use _url at all.
jdl
jdl: that must be due to the many things I've tried to accomplish this, and maybe I deleted the "_url" syntax accidentally. Adding it or "_path" is not solving the problem.
Brian Roisentul
Alright. Go ahead and post your real code, and the relevant output from "rake routes". It's hard to help you debug code without being able to see it.
jdl
Having editing that. I've wrote everything as I have it on my website. Any help will be appreciated.
Brian Roisentul