Sha256: e74815daa36532d7a288a7e1e12ff3497690be9555bc9ccc2a1b65946352bd2a

Contents?: true

Size: 768 Bytes

Versions: 9

Compression:

Stored size: 768 Bytes

Contents

module Georgia
  class User < ActiveRecord::Base
    devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable

    attr_accessible :first_name, :last_name, :email, :password, :password_confirmation, :remember_me, :role_ids

    has_and_belongs_to_many :roles, class_name: Georgia::Role

    def has_role? role
      return false unless role
      @role_names ||= roles.map(&:name)
      @role_names.include? role.to_s.titleize
    end

    scope :admins, includes(:roles).where(georgia_roles: {name: 'Admin'})
    scope :editors, includes(:roles).where(georgia_roles: {name: 'Editor'})

    def name
      [first_name, last_name].join(' ')
    end

    def roles_names
      roles.map(&:name).join(', ')
    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
georgia-0.7.8 app/models/georgia/user.rb
georgia-0.7.7 app/models/georgia/user.rb
georgia-0.7.6 app/models/georgia/user.rb
georgia-0.7.5 app/models/georgia/user.rb
georgia-0.7.4 app/models/georgia/user.rb
georgia-0.7.3 app/models/georgia/user.rb
georgia-0.7.2 app/models/georgia/user.rb
georgia-0.7.1 app/models/georgia/user.rb
georgia-0.7.0 app/models/georgia/user.rb