Namespaced routing

Hello Rails Talk people

(I am using rails 2.3.5, with ruby 1.8.7)
When I
    ruby script/generate scaffold admin/category name:string
    ruby script/generate scaffold Admin::category name:string
and then
    rake db:migrate:up VERSION=20091206005933 whatever...
and configure in routes.rb
  map.namespace :admin do |admin|
    admin.resources :categories
then, when going to
then following error is produced:
    Mysql::Error: Table 'sr22x3_development.categories' doesn't exist:
SELECT * FROM `categories`
Now, of course this error is produced, because, after all, there is
indeed NO table
named "categories". That's because the database that the migrations
is named
Unless I go through a massive renaming of components, such as
suggested by
then nothing works. (Slobodan's fix, from his site, is given below.)

I thought that subdirectory and Namespace routing was supposed to be

Regards, all
Maurice Yarrow

Slobodan's fix, from his site, is quoted below:

Here is the easiest way I found so far to accomplish this. This
example generates categories model
and controllers for it.

./script/generate controller admin/categories
./script/generate scaffold category name:string

This will generate an empty controller in admin namespace and a
scaffolded resource for front-end

Now we have everything generated we just need to make it work with
admin controller and not with

move all templates from app/views/categories to app/views/admin/
copy all functions from categories_controller.rb to admin/
add namespace for admin controller in routes.rb:
map.namespace :admin do |admin|
  admin.resources :categories
In admin/categories_controller.rb replace in 3 places redirect_to
calls to work with admin namespace.
It will have something like redirect_to(@category), but to work with
namespace it needs to have
redirect_to([:admin, @category])
make similar changes in all templates, i.e. make it work within an
admin namespace. You need to
make following changes:
form_for(@category) => form_for([:admin, @category])
<%= link_to ‘Show’, @category %> => <%= link_to ‘Show’, [:admin,
@category] %>
categories_path => admin_categories_path
edit_category_path(@category) => edit_admin_category_path(@category)
new_category_path => new_admin_category_path
That’s it. Now you’ll have /admin/categories for all administrative
tasks and you have a free controller
for front-end actions.
You might wonder why not just generate scaffold for admin/categories…
The reason is that you’ll also
get a model that is namespaced in admin (i.e. model would be
Admin::Category). Scaffolded views
also wouldn’t work as it seems that generator doesn’t take into
account the fact that you are using a

Hello further, Rails Talk people

First: correcting a typo on line 20:
(line 20:) 'named "categories". That's because the database that
the migrations'
The word 'database' in the above should (obviously) have been 'table'.

Concerning Namespaced and subdirectory scaffold generation and
Looking further at various blogs, I see that in
duzzell wrote:
I'm having the same problem. The scaffold generator doesn't seem to
distinquish between namespaces and nested models.
I generate a scaffold in a namespace the same way you do. Then I have
1 move the model.rb file to it's parent directory
2 remove the namespace:: prefix from the table name in the migration
3 modify references to the table in the controller to remove the
namespace:: prefix
4 modify the resources statement in the routes.rb file to put the new
model in the namespace
5 modify the paths in the views to include the namespace_ prefix

This above approach, which removes the namespace prefix from
everywhere it
shouldn't have been, is the complementary approach to Slobodan's,
which adds
the namespace prefix everywhere it should have been but wasn't.
of course, what one believes to be the appropriate approach.)

Scanning to the bottom of Slobodan's article from September, 2008, I
blog responses dating till as recently as August, 2009, which all tend
to imply
that the Rails 'generate scaffold admin/category' result had not been
consistent till at least Aug, 09.
Doing a search on the issue in the Rails Talk group, there is a post
this just a day before mine,

So, Namespaced and subdir scaffold generation
appears to still be a broken functionality. (The routing does not
to be an issue here.)
So, at this point, I am willing to believe that this is actually a
Rails bug of sorts
I didn't see a search for the Developer bug-fix list at
so I couldn't ascertain if this is an open issue.

Maurice Yarrow