Named routes in admin namespace

Hi,

I have a controller Admin::Categories in folder controllers/admin

I have a views/admin/categories/index.html.erb which contains:
<%= link_to ‘New category’, new_category_path %>

now if my routes.rb contains:
map.resources :categories

Then the generated url does not have /admin/ on the front ie it is:
/categories/new which does not work as the controller is in /admin

If I do something that seems to be suggested in the comments in
routes.rb ie:
map.namespace :admin do |admin|
admin.resources :categories
end

I get:
undefined local variable or method `new_category_path’ for
#ActionView::Base:0xb6fb5854

How do I get these fancy named routes to work in the admin namepace?
I could have bunged in :controller=>‘categories’ , :action=>‘new’
However we are told that these named routes are smarter…?

Any help appreciated
George

If u want to get the url like admin/categories/new then change ur link
as
<%= link_to new_admin_category_path(@admin) %>

Thanks for that.

<%= link_to new_admin_category_path%> (without the @admin)
works.

However I dont want to change all the links in all the view files!
You must be able to generate the scaffold and tell it that it is in
Admin namespace so that it does it for you?

Otherwise I may as well just convert it
to :controller,… :action… at least that is easy to read and
understand.

Cheers
George

This has a good tut… on rails 2.0 and specifically has examples of
the namespace problem. I had the same issue and just found it.