Forum: Ruby on Rails link_to and routing question

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.
Allen W. (Guest)
on 2008-12-15 05:27
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...

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?
Patrick D. (Guest)
on 2008-12-15 14:47
(Received via mailing list)
On Sun, Dec 14, 2008 at 10:27 PM, Allen W. <
removed_email_address@domain.invalid> 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
Allen W. (Guest)
on 2008-12-15 16:17
Patrick D. wrote:
> On Sun, Dec 14, 2008 at 10:27 PM, Allen W. <
> removed_email_address@domain.invalid> 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
Patrick D. (Guest)
on 2008-12-15 17:04
(Received via mailing list)
> {:action=>"index", :controller=>"roles"}
>                                    formatted_new_role GET
>                                        formatted_role GET
> /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
This topic is locked and can not be replied to.