Eric K
Eric K

Reputation: 277

Multiple controllers with a single model

I'm setting up a directory application for which I need to have two separate interfaces for the same Users table. Basically, administrators use the Users controller and views to list, edit, and add users, while non-admins need a separate interface which lists users in a completely different manner. To do this, would I be able to just set up another controller with different views but which accesses the Users model?

Sorry if this is a simple question, but I've had a hard time finding how to do this.

Upvotes: 5

Views: 1515

Answers (1)

alex.zherdev
alex.zherdev

Reputation: 24174

Why not put the admin part into a separate namespace - you would have Admin::UsersController with views in app/views/admin/users/. And your users would go to UsersController with its own views in app/views/users/.

The routing is defined like this:

map.namespace :admin do |admin|
  admin.resources :users
end


map.resources :users

And can be got to via admin_users_path and users_path

Upvotes: 7

Related Questions