Schneller
2007-Oct-29 06:45 UTC
Two RESTful routes to same controller - best way to implement
I have a controller that needs to render two different layouts depending on the current path, but otherwise performs all the same actions. The routes for the controller are: /bars /foos/5/bars Both need to call the same controller. The rub, however, is that in my views I don''t want to use logic everywhere to determine which named route to call depending on whether @current_foo is set (the id of the current foo). Right now I have many bars_url() and bar_url(@current_bar) routes - these should generate the proper route based on whether the current path is /foos/:id/ or just /. The only solution I see is to override all the named routes for ''bar'' in a helper, and include that helper in my application controller (since these routes are used in controllers as well), but that doesn''t seem a clean solution. Is there any way to do this? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Gerjan Stokkink
2007-Oct-29 11:23 UTC
Re: Two RESTful routes to same controller - best way to impl
Maybe resources_controller (http://plugins.ardes.com/doc/resources_controller/) is what you''re looking for? -- 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 -~----------~----~----~----~------~----~------~--~---
Schneller
2007-Oct-29 15:18 UTC
Re: Two RESTful routes to same controller - best way to impl
Thanks for the reply, but we already implemented everything that does. I''m asking more about the actual routes - having two routes of the same name doesn''t work, so is there a way to add some logic to determine which route to use based on the value of an instance variable? On Oct 29, 4:23 am, Gerjan Stokkink <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Maybe resources_controller > (http://plugins.ardes.com/doc/resources_controller/) > is what you''re looking for? > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Schneller
2007-Oct-29 15:26 UTC
Re: Two RESTful routes to same controller - best way to impl
As a further example, to accomplish two routes to same the controller, you usually have to do a name_prefix: so /bars is bars_url /foo/5/bars is foo_bars_url I want to just use bars_url everywhere - shouldn''t there be a way to determine which route to use based on whether a parameter us set in the current path? On Oct 29, 8:18 am, Schneller <andh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks for the reply, but we already implemented everything that > does. I''m asking more about the actual routes - having two routes of > the same name doesn''t work, so is there a way to add some logic to > determine which route to use based on the value of an instance > variable? > > On Oct 29, 4:23 am, Gerjan Stokkink <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > > Maybe resources_controller > > (http://plugins.ardes.com/doc/resources_controller/) > > is what you''re looking for? > > -- > > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---