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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 ) On Wed, Oct 8, 2008 at 8:40 PM, amrita <amrita.pati-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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 > > >-- Maurício Linhares http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en) João Pessoa, PB, +55 83 8867-7208 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thank you! On Oct 8, 6:56 pm, "Maurício Linhares" <mauricio.linha...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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 ) > > > > On Wed, Oct 8, 2008 at 8:40 PM, amrita <amrita.p...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > 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 > > -- > Maurício Linhareshttp://alinhavado.wordpress.com/(pt-br) |http://blog.codevader.com/(en) > João Pessoa, PB, +55 83 8867-7208--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---