micro-blogger/app/models/user.rb

43 lines
954 B
Ruby
Raw Normal View History

2018-11-10 18:46:47 -06:00
# frozen_string_literal: true
# == Schema Information
#
# Table name: users
#
# id :integer not null, primary key
# display_name :string not null
# email :string not null
# password_digest :string not null
# role :integer default("author"), not null
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_users_on_email (email)
#
class User < ApplicationRecord
has_secure_password
2018-11-11 10:12:43 -06:00
has_many :blogs, dependent: :destroy
2018-11-10 18:46:47 -06:00
validates :display_name, presence: true
validates :email, presence: true, email_format: true, uniqueness: true
validates :password_confirmation, presence: true, if: ->(m) { m.password.present? }
validates :role, presence: true
enum role: {
author: 0,
admin: 2
}
def acts_as_admin?
admin?
end
def acts_as_author?
admin? || author?
end
end