Link_to problem in RoR 2.0

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!

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

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”

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

Thorsten M. wrote:

<%= link_to_unless_current “Search by Name”,
search_by_name_customers_path()
-%>

Perfect! That did the trick! Thanks so much.

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?

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?

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() -%>

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() -%>