3
votes

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?

enter image description here

1

1 Answers

2
votes

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.