# Basic routing question

**URL:** <https://www.ruby-forum.com/t/basic-routing-question/142309>\
**Category:** Rails\
**Created:** [July 6, 2008, 4:47pm UTC](https://www.ruby-forum.com/t/basic-routing-question/142309 "2008-07-06T16:47:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lazylester](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/22d042/32.png) [@lazylester](https://www.ruby-forum.com/u/lazylester)\
**Post date:** [July 6, 2008, 4:47pm UTC](https://www.ruby-forum.com/t/basic-routing-question/142309/1 "2008-07-06T16:47:17Z")

</div>

Sorry for such a basic question… total neophyte here!

I’ve put a new action “foobar” in my “things” actioncontroller. I want  
to link to this action in a linkto function… so: \<% link\_to “go to  
foobar”, :action=\>“foobar” %\>. The html href produced is /things/foobar

Problem is the default routing interprets this as being routed to the  
“things” controller, “show” action, with “id” = “foobar”.

How can I override this default interpretation and create a link to my  
custom “foobar” action?

thanks in advance for any assistance you can provide

---

<div class="post-metadata">

**Author:** ![lazylester](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/22d042/32.png) [@lazylester](https://www.ruby-forum.com/u/lazylester)\
**Post date:** [July 6, 2008, 5:43pm UTC](https://www.ruby-forum.com/t/basic-routing-question/142309/2 "2008-07-06T17:43:03Z")

</div>

Hi Les,  
I had this problem recently and I think I can help.  
It turns out that you have to map every new controller that you create  
in your config/routes.rb. Open it and include a line like this in the  
map block but above all other lines (order matters here):

map.resources :model\_name\_in\_plural, :collection =\> {:action1  
=\>:get, :action2 =\> :get, …, :actionN =\> :get}

example:

map.resources :clients, :collection =\> {:search =\> :get, :upgrade  
=\> :get}

I hope I has of help.

On Jul 6, 4:47 pm, Les N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![lazylester](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/22d042/32.png) [@lazylester](https://www.ruby-forum.com/u/lazylester)\
**Post date:** [July 6, 2008, 9:18pm UTC](https://www.ruby-forum.com/t/basic-routing-question/142309/3 "2008-07-06T21:18:13Z")

</div>

Thanks for the suggestion, Abel,

that wasn’t quite the solution that worked for me, since I was just  
adding an action to an existing controller, vs. adding a new controller.

The solution turned out to be achieved by playing with the sequence of  
the mappings in routes.rb. I understand why the order is important but  
not why it solved this particular problem.

Abel, your suggestion led me to the right solultion, thanks

Les
