Add role to users

This commit is contained in:
riggraz
2019-08-19 10:37:45 +02:00
parent fb924c9e75
commit b854562ca1
3 changed files with 14 additions and 1 deletions

View File

@@ -1,4 +1,11 @@
class User < ApplicationRecord
enum role: [:user, :moderator, :admin]
after_initialize :set_default_role, if: :new_record?
def set_default_role
self.role ||= :user
end
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable,
:confirmable

View File

@@ -0,0 +1,5 @@
class AddRoleToUsers < ActiveRecord::Migration[6.0]
def change
add_column :users, :role, :integer
end
end

View File

@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2019_08_18_162602) do
ActiveRecord::Schema.define(version: 2019_08_18_191513) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -27,6 +27,7 @@ ActiveRecord::Schema.define(version: 2019_08_18_162602) do
t.string "unconfirmed_email"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.integer "role"
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true