Forum: Ruby on Rails new controller actions and url_for

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
738429ce64c60f95e64f8f393976a29f?d=identicon&s=25 amrita (Guest)
on 2008-10-09 01:41
(Received via mailing list)
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?sor...

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
A91bd6cef23eb3516245a092e196c4da?d=identicon&s=25 Maurício Linhares (mauricio)
on 2008-10-09 03:57
(Received via mailing list)
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@gmail.com> wrote:
>
> http://myserver.mydomain.org:8080/species/list?sor...
>
> 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
738429ce64c60f95e64f8f393976a29f?d=identicon&s=25 amrita (Guest)
on 2008-10-09 19:48
(Received via mailing list)
Thank you!

On Oct 8, 6:56 pm, "Maurício Linhares" <mauricio.linha...@gmail.com>
This topic is locked and can not be replied to.