Answer the question
In order to leave comments, you need to log in
How to correctly separate access to views for different roles on Rails 4?
There is an application.
It is assumed that there are several roles, the functionality of roles is very different, and therefore working with the visibility of view elements is inconvenient and cumbersome.
What I would like to get:
For each role, a separate views folder. General form of registration and authorization for all.
Access to views should be restricted to a role. One user can have only one role.
For example:
Roles: Manager, Manager, Head
- views
-Manage
-rootviews1.html.erb
-views1.html.erb
-views2.html.erb
-Director
-rootviews2.html.erb
-views3.html.erb
-views4.html.erb
-Control
-rootviews3.html.erb
-views5.html.erb
-views6.html.erb
Answer the question
In order to leave comments, you need to log in
You need the prepend_view_path method , in which, depending on the role, set the desired path.
apidock.com/rails/AbstractController/ViewPaths/Cla...
If you have different views for different roles, then most likely the functionality in these views is different. Perhaps, in this case, it is worth thinking about spreading everything over different controllers. Then the problem with views will disappear by itself.
class Manage::SomeController < ...
layout 'manage_application'
end
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question