Skip to content

Instantly share code, notes, and snippets.

@fresh5447
Created March 3, 2014 18:27
Show Gist options
  • Select an option

  • Save fresh5447/9331394 to your computer and use it in GitHub Desktop.

Select an option

Save fresh5447/9331394 to your computer and use it in GitHub Desktop.
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :confirmable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation, :remember_me, :name,
has_many :posts
before_create :set_member
ROLES = %w[member moderator admin]
def role?(base_role)
role.nil? ? false : ROLES.index(base_role.to_s) <= ROLES.index(role)
end
private
def set_member
self.role = 'member'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment