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.
No, you use a single controller method to grab the data from both models.
Yes, It is possible to share a view across multiple controllers by putting a view into the shared folder. By doing like this, you can automatically make the view available across multiple controllers.
Yes we can create multiple controllers in Spring MVC.
You need a controller just when you have request actions on the relative model; When a model is just for data calculation and basic business logic implementation, don't generate the controller.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With