Skip to content

Latest commit

 

History

History
118 lines (82 loc) · 1.83 KB

TheRoleInstallation.md

File metadata and controls

118 lines (82 loc) · 1.83 KB

[ Back to TheRole ]


TheRole. Installation

0. Gemfile

gem 'the_role', '~> 3.0.0'

or

# only API
gem 'the_role_api', '~> 3.0.0'

and after that

bundle

1. Change User migration file

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

2. Install TheRole migration file

bundle exec rake the_role_engine:install:migrations

3. Invoke migrations

rake db:migrate

4. Change User model

class User < ActiveRecord::Base
  include TheRole::Api::User

  # ... code ...
end

5. Create Role model

bundle exec rails g the_role install

6. Setup TheRole gem

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

7. Create admin role

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!


[ Back to TheRole ]