gem 'the_role', '~> 3.0.0'
or
# only API
gem 'the_role_api', '~> 3.0.0'
and after that
bundle
Add a role_id:integer
field to your User Model
def self.up
create_table :users do |t|
t.string :login
t.string :email
t.string :crypted_password
t.string :salt
# !!! TheRole field !!!
t.integer :role_id
t.timestamps
end
end
bundle exec rake the_role_engine:install:migrations
rake db:migrate
class User < ActiveRecord::Base
include TheRole::Api::User
# ... code ...
end
bundle exec rails g the_role install
config/initializers/the_role.rb
TheRole.configure do |config|
# [ Devise => :authenticate_user! | Sorcery => :require_login ]
config.login_required_method = :authenticate_user!
# layout for Management panel
config.layout = :the_role_management_panel
# config.default_user_role = nil
# config.first_user_should_be_admin = false
# config.access_denied_method = :access_denied
# config.destroy_strategy = :restrict_with_exception # can be nil
end
rake db:the_role:admin
Now you can make any user an Admin via rails console
, for instance:
User.first.update( role: Role.with_name(:admin) )
User.first.admin? # => true
You are in deal!
Thanks for using TheRole!