Created
March 3, 2014 14:17
-
-
Save pluralism/9325799 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
| User model | |
| class User < ActiveRecord::Base | |
| # Include default devise modules. Others available are: | |
| # :confirmable, :lockable, :timeoutable and :omniauthable | |
| devise :database_authenticatable, :registerable, | |
| :recoverable, :rememberable, :trackable, :validatable | |
| attr_accessible :name, :email, :password, :password_confirmation, :role | |
| belongs_to :userable, :polymorphic => true | |
| # Checks if a given user has "role" permission | |
| def is?(role) | |
| self.role == role.to_s | |
| end | |
| end | |
| Admin model | |
| class Admin < User | |
| has_one :user, :as => :userable | |
| attr_accessible :user | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment