# Routing question, nested resources

**URL:** <https://www.ruby-forum.com/t/routing-question-nested-resources/109861>\
**Category:** Rails\
**Created:** [July 19, 2007, 6:40pm UTC](https://www.ruby-forum.com/t/routing-question-nested-resources/109861 "2007-07-19T18:40:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cidol](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/54ee81/32.png) [@cidol](https://www.ruby-forum.com/u/cidol)\
**Post date:** [July 19, 2007, 6:40pm UTC](https://www.ruby-forum.com/t/routing-question-nested-resources/109861/1 "2007-07-19T18:40:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cidol](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/54ee81/32.png) [@cidol](https://www.ruby-forum.com/u/cidol)\
**Post date:** [July 20, 2007, 6:33am UTC](https://www.ruby-forum.com/t/routing-question-nested-resources/109861/2 "2007-07-20T06:33:44Z")

</div>

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.

> **[Pete Yandell — Principal Engineer / Architect](https://notahat.com/)**
>
> Pete Yandell is an experienced Principal Software Engineer and Architect based in Melbourne, Australia.

---

<div class="post-metadata">

**Author:** ![cidol](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/54ee81/32.png) [@cidol](https://www.ruby-forum.com/u/cidol)\
**Post date:** [July 20, 2007, 7:29am UTC](https://www.ruby-forum.com/t/routing-question-nested-resources/109861/3 "2007-07-20T07:29:48Z")

</div>

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
