Basic routing question

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

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}


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

I hope I has of help.

On Jul 6, 4:47 pm, Les N. [email protected]

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


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs