C
C
Chronic 862016-06-01 11:03:38
Ruby on Rails
Chronic 86, 2016-06-01 11:03:38

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

I looked in the direction of Custom Resolvers, but I found information on implementation only for Rails 3, maybe there is more recent information somewhere? Or other implementation methods?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Sidorov, 2016-06-01
@morr

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

Admin::SomeController
Director::SomeController

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question