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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 Nightingill
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> 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
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---