I am building an RESTful search application in Rails. Unfortunately I can''t take advantage of map.resources routing because the application has no models (it communicates with a SOAP service). So I am building a REST architecture from scratch. I have 5 custom routes to emulate RESTful nesting of resources. However, I have to duplicate every entry to be able to catch whether or not the resource is requested with a format. So I have to have 10 route entries... map.connect ''parent/:parentid/child/:childid.:format'', :controller => ''child'', :action => ''show'', :conditions => {:method => :get} map.connect ''parent/:parentid/child/:childid'', :controller => ''child'', :action => ''show'', :conditions => {:method => :get} ... Does anybody have any suggestions on how I can set this up so I don''t repeat myself? Cheers, Stephanie --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Trevor Squires
2007-Jun-13 19:29 UTC
Re: Manual route redundancy with .:format (REST from scratch)
On 6/13/07, stephanie <ginormous-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > I am building an RESTful search application in Rails. Unfortunately I > can''t take advantage of map.resources routing because the application > has no models (it communicates with a SOAP service). So I am building > a REST architecture from scratch.map.resources is not tightly bound to models (or the naming convention for controllers, as it happens) map.resources :wibbles, :controller => ''something_arbitrary'' your something_arbitrary_controller.rb can do whatever it wants - it''s *your* code. HTH, Trevor -- -- Trevor Squires http://somethinglearned.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 -~----------~----~----~----~------~----~------~--~---
stephanie
2007-Jun-13 20:00 UTC
Re: Manual route redundancy with .:format (REST from scratch)
Thanks for the reply. I used map.resources and it worked fine until I began nesting my resources. The syntax for nesting map.resources does not seem to work without models. The issue I have with map.resources is it creates several routes which aren''t applicable to my application. For instance, I have a few controllers which should only be accessible with a GET since they are results from a web service. The POST, PUT, DELETE + new and edit are not needed. -Stephanie On Jun 13, 12:29 pm, "Trevor Squires" <tre...-k8q5a0yEZAgS+FvcfC7Uqw@public.gmane.org> wrote:> On 6/13/07, stephanie <ginorm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I am building an RESTful search application in Rails. Unfortunately I > > can''t take advantage of map.resources routing because the application > > has no models (it communicates with a SOAP service). So I am building > > a REST architecture from scratch. > > map.resources is not tightly bound to models (or the naming convention > for controllers, as it happens) > > map.resources :wibbles, :controller => ''something_arbitrary'' > > your something_arbitrary_controller.rb can do whatever it wants - it''s > *your* code. > > HTH, > Trevor > > -- > -- > Trevor Squireshttp://somethinglearned.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 -~----------~----~----~----~------~----~------~--~---
Jacob Atzen
2007-Jun-13 20:06 UTC
Re: Manual route redundancy with .:format (REST from scratch)
stephanie wrote:> > Thanks for the reply. I used map.resources and it worked fine until I > began nesting my resources. The syntax for nesting map.resources does > not seem to work without models. The issue I have with map.resources > is it creates several routes which aren''t applicable to my > application. For instance, I have a few controllers which should only > be accessible with a GET since they are results from a web service. > The POST, PUT, DELETE + new and edit are not needed.I''m curious why this would be a problem? If you don''t define the corresponding methods in your controller you should be fine? Or am I missing something? -- Cheers, - Jacob Atzen --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Trevor Squires
2007-Jun-13 20:16 UTC
Re: Manual route redundancy with .:format (REST from scratch)
On 6/13/07, stephanie <ginormous-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks for the reply. I used map.resources and it worked fine until I > began nesting my resources. The syntax for nesting map.resources does > not seem to work without models. The issue I have with map.resourcesI''m not sure how it wouldn''t work without models - as I said, map.resources has nothing to do with models really. I''ll hazard a guess tho: is it something like you want /foo (foo_controller) and /foo/bar (bar_controller)? If that''s what you''re talking about, then /foo is a map.resource (note the singular). So unless what I''ve said above (or what *you* said below) explains why it doesn''t work for you, maybe you could expand on this a bit?> is it creates several routes which aren''t applicable to my > application. For instance, I have a few controllers which should only > be accessible with a GET since they are results from a web service. > The POST, PUT, DELETE + new and edit are not needed.Yeah, I can understand why you wouldn''t want them. I guess it''s a tradeoff between the convenience of map.resources with a controller that only has index/show methods vs the extra (and un-used) routes and url helpers. If the extra routes and helpers really offend you then you could whip up a little helper or two that generates routes the way you want - after all, that''s what map.resources is (see resources.rb in the rails source). HTH, Trevor -- -- Trevor Squires http://somethinglearned.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 -~----------~----~----~----~------~----~------~--~---
stephanie
2007-Jun-13 21:27 UTC
Re: Manual route redundancy with .:format (REST from scratch)
Thanks, this discussion has been really helpful. I am not sure why it didn''t work when I nested it. Perhaps it has to do with mapping associations in the resources.rb. It was awhile ago, so there might have been singular issue. At this point I think I''ve decided I want to implement my own routes. I might refer to resources.rb to create my own helper. Rails map.resources is a great template for how I''d want to do RESTful routes 95% of the time. However, there are times when the conventions breakdown for a particular resource-oriented service. -Stephanie On Jun 13, 1:16 pm, "Trevor Squires" <tre...-k8q5a0yEZAgS+FvcfC7Uqw@public.gmane.org> wrote:> On 6/13/07, stephanie <ginorm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Thanks for the reply. I used map.resources and it worked fine until I > > began nesting my resources. The syntax for nesting map.resources does > > not seem to work without models. The issue I have with map.resources > > I''m not sure how it wouldn''t work without models - as I said, > map.resources has nothing to do with models really. > > I''ll hazard a guess tho: is it something like you want /foo > (foo_controller) and /foo/bar (bar_controller)? If that''s what you''re > talking about, then /foo is a map.resource (note the singular). > > So unless what I''ve said above (or what *you* said below) explains why > it doesn''t work for you, maybe you could expand on this a bit? > > > is it creates several routes which aren''t applicable to my > > application. For instance, I have a few controllers which should only > > be accessible with a GET since they are results from a web service. > > The POST, PUT, DELETE + new and edit are not needed. > > Yeah, I can understand why you wouldn''t want them. I guess it''s a > tradeoff between the convenience of map.resources with a controller > that only has index/show methods vs the extra (and un-used) routes and > url helpers. > > If the extra routes and helpers really offend you then you could whip > up a little helper or two that generates routes the way you want - > after all, that''s what map.resources is (see resources.rb in the rails > source). > > HTH, > Trevor > > -- > -- > Trevor Squireshttp://somethinglearned.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 -~----------~----~----~----~------~----~------~--~---