I followed rolify's tutorial learnt some basic usages. https://github.com/RolifyCommunity/rolify/wiki/Devise---CanCanCan---rolify-Tutorial
For now I the only way I can do to create role is something like user.add_role "admin" in console.
What I want is to create roles by adding resources' actions, then admin user is able to assign roles to users.
I do not know how to achieve this, I made a draft to show my purpose.
Anybody could give me some ideas to make this?

create a model:
class Role < ActiveRecord::Base
has_and_belongs_to_many :users, :join_table => :users_roles
belongs_to :resource, :polymorphic => true
validates :resource_type,
:inclusion => { :in => Rolify.resource_types },
:allow_nil => true
scopify
end
Use that model as regular in form. This way you'll be able to create new roles.
If you want to add roles through user model, from e.g. dropdown select, grab Roles.all and pass it to your select.
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