"User state" in Ruby on Rails application?

Lord, tell me beginner how to create a "custom environment"? What I mean by that. Registered user can add (register) a user from your admin panel, assign them rights to different levels (author, reviewer, content Manager). So within one project it was possible to dynamically create users and assign rights to other users.
Example Is Pivotal Tracker. Here you can add to each project user, to limit their rights. We need some faded likeness.
July 4th 19 at 23:18
2 answers
July 4th 19 at 23:20
I'm not sure if I understand what you need eventually, but can be realized in the following way:

If you want to bother to write my own authentication, then how it from scratch to make well-described here:


If lazy, you can use devise gem (https://github.com/plataformatec/devise) and when a model is created to prescribe her an extra field "role".

Accordingly then create a model "Right".

rails generate model Permission edit:boolean view:boolean delete:boolean + what else comes to mind


Create a has_and_belongs_to_many relation
rails generate model user UserPermission:permission references:references


For example you have a project open at once in edit template

=form_for @project do |f|
some code
 =f.collection_select(:permission_ids, Permission.all, :id, :permission_title, {include_blank: false, :include_hidden => false, :selected => @project.permissions.map(&:id)}, { class: 'there's some css', :multiple => true})


If you want to restrict access rights only for this project, the model UserPermission add the field project_id
rails generate model user UserPermission:permission references:references project_id:integer


and in form code
=form_for @project do |f|
some code
 =f.collection_select(:permission_ids, Permission.all, :id, :permission_title, {include_blank: false, :include_hidden => false, :selected => @project.permissions.map(&:id)}, { class: 'there's some css', :multiple => true})
 =f.fields_for :user_permission do |s|
 =s.hidden_field :project_id, value: @project.id


The code was written from head, plus not quite sure I fully understand the problem, so I ask not to be lynched, if not 100% things.
July 4th 19 at 23:22
Apparently we are talking about a bunch of gems Devise(authentication) and CanCanCan(administration privileges)

Find more questions by tags RubyRuby on Rails