Hi, A recent thread on the ruby list has got me thinking about what a controller would look like for nested resources.> map.resources :houses do |house| > house.resources :walls, :has_many => :damages > house.resources :windows, :has_many => :damages > house.resources :doors, :has_many => :damages > house.resources :damages > end > > The :damages resource appears four times, touching every other > resource and the entire application seems to hinge on the concept > Damage. > > However, in terms of template and controller lines, Damage probably > (simplistically) only accounts for about 20% the application total.What would the damages controller look like in this situation? How much, and what code goes into determining what objects are to be setup? For my project I have a situation where I have map.resources :books, :has_many => :clips /books/1/clips This is fine, I can deal with this, but I would also like another part where I can look into others books /public/username/books/1/clips But I don''t really know what the controller should look like to set this up. Any tips or links to discussion on this would be great Cheers Daniel <http://www.techsmith.com/featured/snag> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Rob Biedenharn
2007-Jun-14 00:49 UTC
Re: Nested Resources. What does the controller look like?
On Jun 13, 2007, at 7:53 PM, Daniel N wrote:> Hi, > > A recent thread on the ruby list has got me thinking about what a > controller would look like for nested resources. > > > map.resources :houses do |house| > house.resources :walls, :has_many => :damages > house.resources :windows, :has_many => :damages > house.resources :doors, :has_many => :damages > house.resources :damages > end > > The :damages resource appears four times, touching every other > resource and the entire application seems to hinge on the concept > Damage. > > However, in terms of template and controller lines, Damage probably > (simplistically) only accounts for about 20% the application total. > > > What would the damages controller look like in this situation? How > much, and what code goes into determining what objects are to be > setup? > > For my project I have a situation where I have > > map.resources :books, :has_many => :clips > /books/1/clips > > This is fine, I can deal with this, but I would also like another > part where I can look into others books > > /public/username/books/1/clips > > But I don''t really know what the controller should look like to set > this up. > > Any tips or links to discussion on this would be great > > Cheers > DanielNot that I know where the :has_many option on resources is supposed to go. (this would be on your MODEL not the route) Anyway, you can use the #with_options method to automagically add options to all method calls in a block: map.with_options :controller => :libraries do |library| library.borrow ''borrow/:id'', :action => ''borrow'' library.request ''request/:id'', :action => ''request'' end is the same as: map.borrow ''borrow/:id'', :controller => :libraries, :action => ''borrow'' map.request ''request/:id'', :controller => :libraries, :action => ''request'' Look at: http://api.rubyonrails.org/classes/ActionController/Routing.html http://api.rubyonrails.org/classes/ActionController/Resources.html -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Josh Knowles
2007-Jun-14 00:55 UTC
Re: Nested Resources. What does the controller look like?
On 6/13/07, Rob Biedenharn <Rob-GBZH0y1GwQfnZcttdmLDtcI/UQi/AW5J@public.gmane.org> wrote:> > > Not that I know where the :has_many option *on resources* is supposed to > go. (this would be on your MODEL not the route) >In edge rails you can now call has_many and has_one to include nested resources, thus the example is valid. -- Josh Knowles joshknowles-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://joshknowles.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 -~----------~----~----~----~------~----~------~--~---
On 6/14/07, Josh Knowles <joshknowles-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > On 6/13/07, Rob Biedenharn <Rob-GBZH0y1GwQfnZcttdmLDtcI/UQi/AW5J@public.gmane.org> wrote: > > > > > > Not that I know where the :has_many option *on resources* is supposed to > > go. (this would be on your MODEL not the route) > > > > > In edge rails you can now call has_many and has_one to include nested > resources, thus the example is valid. > > > > > -- > Josh Knowles > joshknowles-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > http://joshknowles.comTo tell you the truth, the routing is only a secondary issue for the question at hand. What I''m really after is to know what the damages controller would look like. How does it manage the owning resource is that was called? Cheers --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---