Definition of Wordpress-style roles

Asked

Viewed 60 times

0

I am planning the architecture of a personal project to be implemented using Rails. In it, I wish it was possible to easily modify the access rules of users, as is done in wordpress. I know there is cancan to do this, but I believe it would not serve my need. It is a service-oriented application. Each user will be allowed access only to certain services. I thought about implementing a solution of mine, specific to this need, that allows the application administrator to easily modify the access permissions of users through an administrative interface. Someone would tell me a solution to this?

  • Why do you think Cancan won’t do? There is also https://github.com/elabs/pundit. Both can help to implement a solution p/ your need as they are very basic.

1 answer

0


Well, it’s no secret, it’s the basic, step-by-step:

  1. List users and their role (admin, guest, student, etc...)
  2. By clicking the user can update its function.
  3. When visiting a page check if the user has the permission to view the page.

The user model should have a "role" field that will be checked to the user for viewing or using something that requires authorization.

For example in your view you could do the following:

<% if is_admin(@user) %>
  <%= link_to "Edit", edit_post_path(@post) %>
<% end %>

Depending on the required complexity you can increase what you need.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.