Forum: Ruby on Rails Routing question, nested resources

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ed64926147995b3fce2ed2bc04f94537?d=identicon&s=25 Collin Miller (Guest)
on 2007-07-19 18:40
(Received via mailing list)
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
C9c7a65848f13e2b1a226bbe43bc3672?d=identicon&s=25 Pete Yandell (pete)
on 2007-07-20 06:33
(Received via mailing list)
Collin Miller 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 Yandell
http://notahat.com/
27c170f482104299af279902be0a9c26?d=identicon&s=25 Trevor Squires (Guest)
on 2007-07-20 07:29
(Received via mailing list)
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
This topic is locked and can not be replied to.