Created
March 3, 2014 18:27
-
-
Save fresh5447/9331394 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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