# Link\_to problem in RoR 2.0

**URL:** <https://www.ruby-forum.com/t/link-to-problem-in-ror-2-0/131944>\
**Category:** Rails\
**Created:** [March 14, 2008, 5:04pm UTC](https://www.ruby-forum.com/t/link-to-problem-in-ror-2-0/131944 "2008-03-14T17:04:59Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![newrubygirl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e274bd/32.png) [@newrubygirl](https://www.ruby-forum.com/u/newrubygirl)\
**Post date:** [March 14, 2008, 5:04pm UTC](https://www.ruby-forum.com/t/link-to-problem-in-ror-2-0/131944/1 "2008-03-14T17:04:59Z")

</div>

Hello.

I’ve got code from pre RoR 2.0 that is simply a link that a user clicks  
on to go to a search form and it works great.

\<%= link\_to\_unless\_current “Search by Name”, :action =\> “search\_by\_name”  
-%\>

But in the 2.0 world, this now goes to the show method and it fails  
since it’s looking for an id.

Is there a route or something that I need to add or modify? For this  
model, I just have the standard route - map.resources :customers

Thanks!

---

<div class="post-metadata">

**Author:** ![newrubygirl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e274bd/32.png) [@newrubygirl](https://www.ruby-forum.com/u/newrubygirl)\
**Post date:** [March 14, 2008, 5:16pm UTC](https://www.ruby-forum.com/t/link-to-problem-in-ror-2-0/131944/2 "2008-03-14T17:16:30Z")

</div>

not 100%, but i think this should work:  
map.resources :customers, :collection =\> [“search\_by\_name”]

---

<div class="post-metadata">

**Author:** ![newrubygirl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e274bd/32.png) [@newrubygirl](https://www.ruby-forum.com/u/newrubygirl)\
**Post date:** [March 14, 2008, 5:26pm UTC](https://www.ruby-forum.com/t/link-to-problem-in-ror-2-0/131944/3 "2008-03-14T17:26:48Z")

</div>

Thorsten M. wrote:

> map.resources :customers, :collection =\> [“search\_by\_name”]

Unfortunately, that gives me an error “Couldn’t find Custoemr with  
ID=search\_by\_name”

---

<div class="post-metadata">

**Author:** ![newrubygirl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e274bd/32.png) [@newrubygirl](https://www.ruby-forum.com/u/newrubygirl)\
**Post date:** [March 14, 2008, 5:45pm UTC](https://www.ruby-forum.com/t/link-to-problem-in-ror-2-0/131944/4 "2008-03-14T17:45:11Z")

</div>

hmm, i think for the routes that’s correct, maybe try the path helper of  
ruby 2.0:

\<%= link\_to\_unless\_current “Search by Name”,  
search\_by\_name\_customers\_path()  
-%\>

assuming, you’re not using any more complicated constructs like  
namespaces in your routing, this should work.

otherwise please post:  
the generated html code for that link  
the params returned to controller/action from the development.log

---

<div class="post-metadata">

**Author:** ![newrubygirl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e274bd/32.png) [@newrubygirl](https://www.ruby-forum.com/u/newrubygirl)\
**Post date:** [March 14, 2008, 5:49pm UTC](https://www.ruby-forum.com/t/link-to-problem-in-ror-2-0/131944/5 "2008-03-14T17:49:59Z")

</div>

Thorsten M. wrote:

> \<%= link\_to\_unless\_current “Search by Name”,  
> search\_by\_name\_customers\_path()  
> -%\>

Perfect! That did the trick! Thanks so much.

---

<div class="post-metadata">

**Author:** ![newrubygirl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e274bd/32.png) [@newrubygirl](https://www.ruby-forum.com/u/newrubygirl)\
**Post date:** [March 14, 2008, 7:57pm UTC](https://www.ruby-forum.com/t/link-to-problem-in-ror-2-0/131944/6 "2008-03-14T19:57:01Z")

</div>

Ooops! Something else broke now.

My route looks like this:  
map.resources :customers, :collection =\> [“search\_by\_name”]

I also have a link menu link:  
\<%= link\_to\_unless\_current “List”, :action =\> “list” -%\>

When I click on that link I get this error.  
Couldn’t find Customer with ID=list

In my controller I have a list

def list  
search criteria  
end

Any ideas?

---

<div class="post-metadata">

**Author:** ![newrubygirl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e274bd/32.png) [@newrubygirl](https://www.ruby-forum.com/u/newrubygirl)\
**Post date:** [March 14, 2008, 8:07pm UTC](https://www.ruby-forum.com/t/link-to-problem-in-ror-2-0/131944/7 "2008-03-14T20:07:58Z")

</div>

Thorsten M. wrote:

> just the same as above (replace controller with the right name in  
> plural):  
> map.resources :controllers, :collection =\> [“list”]
> 
> and for the link:  
> \<%= link\_to\_unless\_current “List”, list\_controllers\_path() -%\>

Sorry for not being clearer… these would use the same resource. Can I  
have 2 collection values on 1 resource?

---

<div class="post-metadata">

**Author:** ![newrubygirl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e274bd/32.png) [@newrubygirl](https://www.ruby-forum.com/u/newrubygirl)\
**Post date:** [March 14, 2008, 8:16pm UTC](https://www.ruby-forum.com/t/link-to-problem-in-ror-2-0/131944/8 "2008-03-14T20:16:29Z")

</div>

> Sorry for not being clearer… these would use the same resource. Can I  
> have 2 collection values on 1 resource?

sure, it’s  
map.resources :customers, :collection =\> [“search\_by\_name”, “list”]

and for the link:  
\<%= link\_to\_unless\_current “List”, list\_customers\_path() -%\>

---

<div class="post-metadata">

**Author:** ![newrubygirl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e274bd/32.png) [@newrubygirl](https://www.ruby-forum.com/u/newrubygirl)\
**Post date:** [March 14, 2008, 8:06pm UTC](https://www.ruby-forum.com/t/link-to-problem-in-ror-2-0/131944/9 "2008-03-14T20:06:02Z")

</div>

just the same as above (replace controller with the right name in  
plural):  
map.resources :controllers, :collection =\> [“list”]

and for the link:  
\<%= link\_to\_unless\_current “List”, list\_controllers\_path() -%\>
