Sha256: c67047ca98c2c819e1d98bdf0d4c500b08dea3e4d6dc97ac0e0e8d095919aef5
Contents?: true
Size: 1.3 KB
Versions: 6
Compression:
Stored size: 1.3 KB
Contents
class User include Mongoid::Document include Mongoid::Timestamps::Created field :login field :email field :role field :age, type: Integer field :password, type: String field :provider_uid field :locale belongs_to :site, inverse_of: :users has_many :articles, foreign_key: :author_id, order: :title has_many :comments, dependent: :destroy, autosave: true has_and_belongs_to_many :children, class_name: "User" has_one :record, autobuild: true embeds_one :profile validates :login, presence: true, uniqueness: { scope: :site }, format: { with: /\A[\w\-]+\z/ }, exclusion: { in: ["super", "index", "edit"] } validates :email, uniqueness: { case_sensitive: false, scope: :site, message: "is already taken" }, confirmation: true validates :role, presence: true, inclusion: { in: ["admin", "moderator", "member"] } validates :profile, presence: true, associated: true validates :age, presence: true, numericality: true, inclusion: { in: 23..42 }, on: [:create, :update] validates :password, presence: true, on: [:create, :update] validates :password, exclusion: { in: ->(user) { ['password'] } } validates :provider_uid, presence: true validates :locale, inclusion: { in: ->(user) { [:en, :ru] } } accepts_nested_attributes_for :articles, :comments def admin? false end end
Version data entries
6 entries across 6 versions & 3 rubygems