link_to and routing question

I have the following link_to:

<%= link_to("Remove", {:action => "remove_role_from_account", :role_id
=> role, :account_id => @account}) %>

It generates:
http://myserver.com/roles/remove_role_from_account?account_id=1&role_id=5

But this doesn't match the right default route:

{:action=>"wsdl"} /:controller/:action/:id.:format
              /:controller/:action/:id

So it's not hitting my action "remove_role_from_account" and instead is
try to go to action "show" with the id as "remove_role_from_account"

what am i doing wrong here?

what does the output of:

rake routes

look like?

–wpd

Patrick Doyle wrote:

{:action=>"wsdl"} /:controller/:action/:id.:format
             /:controller/:action/:id

So it's not hitting my action "remove_role_from_account" and instead is
try to go to action "show" with the id as "remove_role_from_account"

what am i doing wrong here?
--

what does the output of:

rake routes

look like?

--wpd

                                   roles GET /roles
{:action=>"index", :controller=>"roles"}
                                       formatted_roles GET
/roles.:format
{:action=>"index", :controller=>"roles"}
                                                       POST /roles
{:action=>"create", :controller=>"roles"}
                                                       POST
/roles.:format
{:action=>"create", :controller=>"roles"}
                                              new_role GET /roles/new
{:action=>"new", :controller=>"roles"}
                                    formatted_new_role GET
/roles/new.:format
{:action=>"new", :controller=>"roles"}
                                             edit_role GET
/roles/:id/edit
{:action=>"edit", :controller=>"roles"}
                                   formatted_edit_role GET
/roles/:id/edit.:format
{:action=>"edit", :controller=>"roles"}
                                                  role GET /roles/:id
{:action=>"show", :controller=>"roles"}
                                        formatted_role GET
/roles/:id.:format
{:action=>"show", :controller=>"roles"}
                                                       PUT /roles/:id
{:action=>"update", :controller=>"roles"}
                                                       PUT
/roles/:id.:format
{:action=>"update", :controller=>"roles"}
                                                       DELETE /roles/:id
{:action=>"destroy", :controller=>"roles"}
                                                       DELETE
/roles/:id.:format
{:action=>"destroy", :controller=>"roles"}
{:action=>"wsdl"}
                                                              /:controller/:action/:id.:format
                                                              /:controller/:action/:id

what does the output of:

rake routes

look like?

–wpd

roles GET /roles

{:action=>“index”, :controller=>“roles”}

                                   formatted_roles GET

/roles.:format

{:action=>“index”, :controller=>“roles”}

                                                   POST   /roles

{:action=>“create”, :controller=>“roles”}

                                                   POST

/roles.:format

{:action=>“create”, :controller=>“roles”}

                                          new_role GET    /roles/new

{:action=>“new”, :controller=>“roles”}

                                formatted_new_role GET

/roles/new.:format

{:action=>“new”, :controller=>“roles”}

                                         edit_role GET

/roles/:id/edit

{:action=>“edit”, :controller=>“roles”}

                               formatted_edit_role GET

/roles/:id/edit.:format

{:action=>“edit”, :controller=>“roles”}

                                              role GET    /roles/:id

{:action=>“show”, :controller=>“roles”}

                                    formatted_role GET

/roles/:id.:format

{:action=>“show”, :controller=>“roles”}

                                                   PUT    /roles/:id

{:action=>“update”, :controller=>“roles”}

                                                   PUT

/roles/:id.:format

{:action=>“update”, :controller=>“roles”}

                                                   DELETE /roles/:id

{:action=>“destroy”, :controller=>“roles”}

                                                   DELETE

/roles/:id.:format

{:action=>“destroy”, :controller=>“roles”}
{:action=>“wsdl”}

                                                          /:controller/:action/:id.:format

                                                          /:controller/:action/:id

In all my humble newbieness, it looks to me like, when you get a URL of the form /roles/something?with_this?and_that, the first pattern that the route table finds that matches that is the pattern that looks like: /roles/:id, so you get routed to the “show” action of the "roles"controller. I know that the routes table is processed in order and the first pattern that matches is the one that triggers the action (which is why the /:controller/:action/:id pattern is always listed last.).

What I don’t know is, why does {:action => “remove_role_from_account”, :role_id => role, :account_id => @account} produce a url of the form: /roles/remove_role_from_account, when you specifically plug in an action of “remove_role_from_account”.

Sorry if this doesn’t help much.

–wpd