Nested Route Issue Rails 2.0

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

You can also go into the actual site 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

http://tagtheplanet.net/mobile/users/1/entries

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'

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.

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!

AndyV wrote:

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!

cpaesleme wrote: