new controller actions and url_for

Hi,

I just defined a new controller action "list" for one of my controllers, let's call it "species". To routes.rb, I added the following entry:

map.resource :species, :member => { :list => :get }

I have a helper method in which I use url_for as follows:

url_for(:controller => 'species', :action => 'list', :params => params.merge({:sort => key, :page => nil}))

When I call this helper method from the view, it completely bypasses the action in the generated URL. I get a URL as follows:

http://myserver.mydomain.org:8080/species?sort=sortparam

What I expect to get is a URL as follows:

http://myserver.mydomain.org:8080/species/list?sort=sortparam

I did a `rake routes | grep list` and I do get the following two lines:

list_species GET /species/ list {:controller=>"species", :action=>"list"} formatted_list_species GET /species/ list.:format {:controller=>"species", :action=>"list"}

Could someone please point out what needs to be corrected for url_for to work properly? Is url_for not finding a route for controller=species and action=list or is there some other problem?

Many thanks! Amrita

What you want is a collection, not a member:

map.resource :species, :collection => { :list => :get }

Also, instead of using url_for, you could use list_species_path( :sort => key, :page => nil )

Thank you!