Sha256: 81b4a781e510211ced4a724d616d99f22ce6a7c9056d8da51f2aca74c9d12124

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

class User < ActiveRecord::Base
  before_create :create_profile
  belongs_to :role
  has_many :blogs, :dependent => :destroy
  has_one :profile, :dependent => :destroy
  has_many :galleries, :dependent => :destroy

  def create_profile
    self.profile ||= Profile.create(:user => self)
  end

  def role?(role)
    if role.kind_of?(Role)
      return role==self.role
    elsif role.is_numeric?
      return self.role_id==role
    else
      return self.role.name.underscore==role.underscore
    end
  end

  def role=(role)
    if role.kind_of? Role
      self.role_id = role.id
    else
      role = role.to_s.camelize
      if role.is_numeric?
        self.role_id= role
      else
        self.role_id= Role.find_by_name(role).id
      end
    end
  end

  def confirm!
    self.confirmed_at = DateTime::now
    save
  end

  # Include default devise modules. Others available are:
  # :token_authenticatable, :confirmable, :lockable and :timeoutable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable,
         :token_authenticatable, :confirmable, :lockable, :timeoutable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wheels-0.0.18 app/models/user.rb