# Nested Route Issue Rails 2.0

**URL:** <https://www.ruby-forum.com/t/nested-route-issue-rails-2-0/133393>\
**Category:** Rails\
**Created:** [March 31, 2008, 7:51am UTC](https://www.ruby-forum.com/t/nested-route-issue-rails-2-0/133393 "2008-03-31T07:51:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cpaesleme](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ecccb3/32.png) [@cpaesleme](https://www.ruby-forum.com/u/cpaesleme)\
**Post date:** [March 31, 2008, 7:51am UTC](https://www.ruby-forum.com/t/nested-route-issue-rails-2-0/133393/1 "2008-03-31T07:51:06Z")

</div>

Hi guys, having an issue with a nested route mapping. Do you have any  
ideas?

Almost done with my app from a Rails book I’m studying, built a  
‘mobile’ subfolder to provide support for mobile devices. Here is the  
route:

map.resources :users,  
:controller =\> ‘mobile/users’,  
:path\_prefix =\> ‘/mobile’,  
:name\_prefix =\> ‘mobile\_’ do |users|  
users.resource :entries,  
:controller =\> ‘mobile/entries’,  
:name\_prefix =\>‘mobile\_’  
end

where a user has several blog entries.

The URL I’m trying to access here is

/mobile/users/1/entries

which according to ‘rake routes’ should give me the index method of  
the mobile/entries controller. However, the above URL ends up taking  
me to the UsersController instead, despite what rake routes is telling  
me. The result is that I end up with the “no action responded to 1”  
error.

If you’d like to have a look at the app, I’ve zipped it up and placed  
it in this address:

[http://tagtheplanet.net/railscoders.zip](http://tagtheplanet.net/railscoders.zip)

You can also go into the actual site [tagtheplanet.net&nbsp;-&nbsp;tagtheplanet Resources and Information.](http://tagtheplanet.net/mobile/)  
and go to Blogs and click on the Admin link at the top to get the same  
error, or use the URL

> **[tagtheplanet.net - tagtheplanet Resources and Information.](http://tagtheplanet.net/mobile/users/1/entries)**
>
> tagtheplanet.net is your first and best source for all of the information you’re looking for. From general topics to more of what you would expect to find here, tagtheplanet.net has it all. We hope you find what you are searching for!

---

<div class="post-metadata">

**Author:** ![cpaesleme](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ecccb3/32.png) [@cpaesleme](https://www.ruby-forum.com/u/cpaesleme)\
**Post date:** [March 31, 2008, 10:33am UTC](https://www.ruby-forum.com/t/nested-route-issue-rails-2-0/133393/2 "2008-03-31T10:33:31Z")

</div>

Hi cpaesleme,  
Try changing “users.resource :entries” to “users.resources :entries”,  
then moving the whole map.resources :users block to a line in the  
routes.rb file, making sure it appears before the default config  
lines:  
map.connect ‘:controller/:action/:id.:format’  
map.connect ‘:controller/:action/:id’

---

<div class="post-metadata">

**Author:** ![cpaesleme](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ecccb3/32.png) [@cpaesleme](https://www.ruby-forum.com/u/cpaesleme)\
**Post date:** [March 31, 2008, 3:04pm UTC](https://www.ruby-forum.com/t/nested-route-issue-rails-2-0/133393/3 "2008-03-31T15:04:18Z")

</div>

If you plan on supporting both mobile and ‘non-mobile’ browsers then  
you probably want to use namespace in routes:

map.namespace :mobile do |mobile|  
mobile.resources :users  
end

map.resources :users

This should give you a ‘default’ routing for ‘normal’ users (PCs) and  
a ‘mobile’ alternative. You’ll have to do the work of determining  
which one is appropriate for any given request. The advantage of  
using namespacing, though, is that it will automatically look in the /  
views/mobile/users folder for the view code.

---

<div class="post-metadata">

**Author:** ![cpaesleme](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ecccb3/32.png) [@cpaesleme](https://www.ruby-forum.com/u/cpaesleme)\
**Post date:** [April 1, 2008, 5:59pm UTC](https://www.ruby-forum.com/t/nested-route-issue-rails-2-0/133393/4 "2008-04-01T17:59:03Z")

</div>

Hey guys,

Thanks for the suggestions. I implemented the namespace, which is  
cleaner and leads to less code, and it generates the correct routes  
and everything, but still mobile\_user\_entries\_url is redirecting to  
the users\_controller instead of the entries\_controller like rake  
routes indicates.

I’ll keep poking around the code, let me know if you think of anything  
else to try!

---

<div class="post-metadata">

**Author:** ![cpaesleme](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ecccb3/32.png) [@cpaesleme](https://www.ruby-forum.com/u/cpaesleme)\
**Post date:** [April 2, 2008, 5:40pm UTC](https://www.ruby-forum.com/t/nested-route-issue-rails-2-0/133393/5 "2008-04-02T17:40:10Z")

</div>

After poking around for another 4 hours, I finally realized that I had  
the

map.connect ‘:controller/:action/:id.:format’  
map.connect ‘:controller/:action/:id’

above the mobile lines, which was causing the app not to see the  
mobile routes correctly. How anticlimactic.

I moved them down to the bottom of the file and now everything works  
fine. Thanks for the namespace trick and for looking at my issue  
guys!
