Sha256: 189e3331e94d3217ebec1a56504f864ff50fede6c6be865ff5b26b73d7f97d0d

Contents?: true

Size: 1.11 KB

Versions: 9

Compression:

Stored size: 1.11 KB

Contents

class User < ActiveRecord::Base
  before_create :create_profile
  belongs_to :role

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

  def self.super_user
    @@super_user ||= User.where(:role_id=>Role::SUPER).first
  end

  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
      self.role_id = role.id
    else
      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

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
wheels-0.0.13 app/models/user.rb
wheels-0.0.11 app/models/user.rb
wheels-0.0.10 app/models/user.rb
wheels-0.0.9 app/models/user.rb
wheels-0.0.8 app/models/user.rb
wheels-0.0.6 app/models/user.rb
wheels-0.0.5 app/models/user.rb
wheels-0.0.4 app/models/user.rb
wheels-0.0.3 app/models/user.rb