map.resources :houses do |house|
house.resources :walls, :has_many => :damages
house.resources :windows, :has_many => :damages
house.resources :doors, :has_many => :damages
The :damages resource appears four times, touching every other
resource and the entire application seems to hinge on the concept
However, in terms of template and controller lines, Damage probably
(simplistically) only accounts for about 20% the application total.
A recent thread on the ruby list has got me thinking about what a controller would look like for nested resources.
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
This is fine, I can deal with this, but I would also like another part where I can look into others books
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
Not 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’
is the same as:
map.borrow ‘borrow/:id’, :controller => :libraries, :action => ‘borrow’
map.request ‘request/:id’, :controller => :libraries, :action => ‘request’
Rob Biedenharn http://agileconsultingllc.com
In edge rails you can now call has_many and has_one to include nested resources, thus the example is valid.
To 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?