I’m new to rails, and trying to develop a system that will have several different types of user. I’m trying to use namespaces to separate these areas, but I want the models to be shared. I’ve created a user object, and I want to be able to edit it from the admin namespace. I’ve scaffolded an Admin::UserController, and defined the routes as:
namespace :admin do
resources :users
end
root :to => "home#index"
When I go to admin/users it shows fine, but clicking ‘Create User’ gave me an NoMethodError, saying it couldn’t find the path users_path. After searching I realised I needed to update my routes.rb to:
resources :users
namespace :admin do
resources :users
end
root :to => "home#index"
Now I can get to the admin/users/new form, but when I post it tries to return to /users. My two questions are: 1. how can I make this work? and 2. am I even approaching this correctly trying to use namespaces in this manner?
You have routes generated for both
/admin/usersand/users. If you want to useAdmin::UsersControlleruseadmin_users_pathand if you wish to useUsersControlleruseusers_pathin your form.I would also like to suggest you to use
rake routescommand if you ever wonder what are the names of the generated routes.