Nested Resources. What does the controller look like?

Hi,

A recent thread on the ruby list has got me thinking about what a
controller
would look like for nested resources.

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

On Jun 13, 2007, at 7:53 PM, Daniel N wrote:

house.resources :damages
What would the damages controller look like in this situation? How

/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

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’
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 B. http://agileconsultingllc.com
[email protected]

On 6/14/07, Josh K. [email protected] wrote:

In edge rails you can now call has_many and has_one to include nested
resources, thus the example is valid.


Josh K.
[email protected]
http://joshknowles.com

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?

Cheers

On 6/13/07, Rob B. [email protected] 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 K.
[email protected]
http://joshknowles.com