# Nested routes

**URL:** <https://www.ruby-forum.com/t/nested-routes/123992>\
**Category:** Rails\
**Created:** [December 23, 2007, 5:30am UTC](https://www.ruby-forum.com/t/nested-routes/123992 "2007-12-23T05:30:09Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonlog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/db5fbb/32.png) [@jonlog](https://www.ruby-forum.com/u/jonlog)\
**Post date:** [December 23, 2007, 5:30am UTC](https://www.ruby-forum.com/t/nested-routes/123992/1 "2007-12-23T05:30:09Z")

</div>

ROR 2.0.2

I have:  
map.resources :blogs do |blog|  
blog.resources :posts  
end

in my routes.rb

I am calling the route as:  
link\_to “(manage)”, posts\_path(@blog)

I get the following error:  
Undefined method `posts\_path’ for #ActionView::Base:0xb74caa38

I am sure it is something stupid, but I can’t figure out what.

Thanks

---

<div class="post-metadata">

**Author:** ![jonlog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/db5fbb/32.png) [@jonlog](https://www.ruby-forum.com/u/jonlog)\
**Post date:** [December 23, 2007, 5:50am UTC](https://www.ruby-forum.com/t/nested-routes/123992/2 "2007-12-23T05:50:37Z")

</div>

path should be blog\_posts\_path, there 's a name prefice since rails 2.  
you can do “rake routes” to check your routes. regards

---

<div class="post-metadata">

**Author:** ![jonlog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/db5fbb/32.png) [@jonlog](https://www.ruby-forum.com/u/jonlog)\
**Post date:** [December 23, 2007, 6:14am UTC](https://www.ruby-forum.com/t/nested-routes/123992/3 "2007-12-23T06:14:33Z")

</div>

And if you want to link to a certain post regardless of which blog it  
belongs to, define map.resources :posts outside of the blog block.

On Dec 23, 2007 3:20 PM, Jean-SÃ©bastien [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > end
> > 
> > Thanks

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

Feel free to add me to MSN and/or GTalk as this email.

---

<div class="post-metadata">

**Author:** ![jonlog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/db5fbb/32.png) [@jonlog](https://www.ruby-forum.com/u/jonlog)\
**Post date:** [December 23, 2007, 7:04pm UTC](https://www.ruby-forum.com/t/nested-routes/123992/4 "2007-12-23T19:04:13Z")

</div>

Thanks to all, I am just learning this REST stuff, and am finally  
getting  
it.

Jon

---

<div class="post-metadata">

**Author:** ![jonlog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/db5fbb/32.png) [@jonlog](https://www.ruby-forum.com/u/jonlog)\
**Post date:** [December 23, 2007, 7:10pm UTC](https://www.ruby-forum.com/t/nested-routes/123992/5 "2007-12-23T19:10:40Z")

</div>

Bala, that throws a syntax error, so something is wrong.

map.resources :blogs,  
has\_many :posts  
end

---

<div class="post-metadata">

**Author:** ![jonlog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/db5fbb/32.png) [@jonlog](https://www.ruby-forum.com/u/jonlog)\
**Post date:** [December 23, 2007, 9:19am UTC](https://www.ruby-forum.com/t/nested-routes/123992/6 "2007-12-23T09:19:14Z")

</div>

On Dec 22, 2007 8:29 PM, Jon G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ROR 2.0.2
> 
> I have:  
> map.resources :blogs do |blog|  
> blog.resources :posts  
> end

This is the old way. The new way:

map.resources :blogs,  
has\_many :posts  
end

> in my routes.rb
> 
> I am calling the route as:  
> link\_to “(manage)”, posts\_path(@blog)

Use rake:routes to list all the available routes and how they are mapped  
to  
an action.

–  
[http://www.rubyplus.org/](http://www.rubyplus.org/)  
Free Ruby Screencasts

---

<div class="post-metadata">

**Author:** ![jonlog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/db5fbb/32.png) [@jonlog](https://www.ruby-forum.com/u/jonlog)\
**Post date:** [December 23, 2007, 7:15pm UTC](https://www.ruby-forum.com/t/nested-routes/123992/7 "2007-12-23T19:15:57Z")

</div>

Jon :

> map.resources :blogs,  
> has\_many :posts  
> end

map.resources :blogs, :has\_many =\> :posts

For better help, please send your questions on the Ruby on Rails Talk  
mailing list.

– Jean-François.

---

<div class="post-metadata">

**Author:** ![jonlog](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/db5fbb/32.png) [@jonlog](https://www.ruby-forum.com/u/jonlog)\
**Post date:** [December 23, 2007, 7:17pm UTC](https://www.ruby-forum.com/t/nested-routes/123992/8 "2007-12-23T19:17:09Z")

</div>

myself :

> Jon :
> 
> > map.resources :blogs,  
> > has\_many :posts  
> > end
> 
> map.resources :blogs, :has\_many =\> :posts
> 
> For better help, please send your questions on the Ruby on Rails Talk  
> mailing list.

Sorry, I thought we were on Ruby T. list !

– Jean-François.
