tags:

views:

373

answers:

2

How does one do namespaced controllers in Merb, for instance to create an admin section to the site? In Rails one would use Admin::CategoriesController, is this similar in Merb or is this another recommended way of doing it?

+2  A: 

The namespace method seems to do it.

This is placed in the routes file (router.rb):

namespace :admin do
  resources :categories
end

This generates routes like:

edit_admin_category - /admin/categories/:id/edit(.:format)
delete_admin_category - /admin/categories/:id/delete(.:format)
admin_categories - /admin/categories(/index)(.:format)
new_admin_category - /admin/categories/new(.:format)
admin_category - /admin/categories/:id(.:format)

I then put my controller in a module like this:

module Admin
  class Categories < Application
    def index
      ...
    end

    .
    .
    .
  end
end

I am not sure if this is the recommended way, any suggestions to this would be great.

Laz
A: 

The above answer is correct, but for what it's worth, I had a hard time trying to make use of the new route with link_to in my views.

I ended up getting this to work:

<%= link_to("Categories Admin", resource(:admin, :categories) %>