Routing question, nested resources


#1

Hey all, love the RoRTalk group

This might just be a general Ruby question, but I ran into the problem
in Rails so I’ll put it out here.

I’m trying to re-use some routing code.

this_and_that = proc { |a_resource|
a_resource.resources :this do |this|
this.resources :that
end
}

map.resources :foos do |foos|
foos.resources :bazs this_and_that
foos.resources :bats this_and_that
end

I’m pretty sure I need to fix these lines:
foos.resources :bazs this_and_that

All the best,
Collin T Miller


#2

Collin M. wrote:

foos.resources :bats this_and_that
end

It’s not at all clear what you expect this to do. This isn’t even valid
Ruby syntax!

Can you explain the result you’re trying to achieve?

Pete Y.
http://notahat.com/


#3

I think what he wants is this:

this_and_that = proc { |a_resource|
a_resource.resources :this do |this|
this.resources :that
end
}

map.resources :foos do |foos|
foos.resources :bazs &this_and_that
foos.resources :bats &this_and_that
end

Note the & before this_and_that.

Trevor