# Link\_to and routing question

**URL:** <https://www.ruby-forum.com/t/link-to-and-routing-question/155636>\
**Category:** Rails\
**Created:** [December 15, 2008, 4:27am UTC](https://www.ruby-forum.com/t/link-to-and-routing-question/155636 "2008-12-15T04:27:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hangingclowns](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5e925/32.png) [@hangingclowns](https://www.ruby-forum.com/u/hangingclowns)\
**Post date:** [December 15, 2008, 4:27am UTC](https://www.ruby-forum.com/t/link-to-and-routing-question/155636/1 "2008-12-15T04:27:51Z")

</div>

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](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?

---

<div class="post-metadata">

**Author:** ![hangingclowns](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5e925/32.png) [@hangingclowns](https://www.ruby-forum.com/u/hangingclowns)\
**Post date:** [December 15, 2008, 1:47pm UTC](https://www.ruby-forum.com/t/link-to-and-routing-question/155636/2 "2008-12-15T13:47:44Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hangingclowns](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5e925/32.png) [@hangingclowns](https://www.ruby-forum.com/u/hangingclowns)\
**Post date:** [December 15, 2008, 3:17pm UTC](https://www.ruby-forum.com/t/link-to-and-routing-question/155636/3 "2008-12-15T15:17:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hangingclowns](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b5e925/32.png) [@hangingclowns](https://www.ruby-forum.com/u/hangingclowns)\
**Post date:** [December 15, 2008, 4:04pm UTC](https://www.ruby-forum.com/t/link-to-and-routing-question/155636/4 "2008-12-15T16:04:09Z")

</div>

> {: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
