Created
March 20, 2014 15:30
-
-
Save orafaelfragoso/9666425 to your computer and use it in GitHub Desktop.
Member e Roles
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 Member < ActiveRecord::Base | |
has_many :roles | |
devise :database_authenticatable, :async, :registerable, | |
:recoverable, :rememberable, :trackable, :validatable, :confirmable | |
def manager? | |
(false if self.role == 0) || true | |
end | |
def managed_members | |
false if self.manager? == false | |
false if self.roles.count == 0 | |
ids = [] | |
self.roles.collect {|i| ids << i.managed_id} | |
self.class.where(id: ids).order('id DESC').load | |
end | |
end |
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 Role < ActiveRecord::Base | |
belongs_to :member | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cara acho que isso:
tu pode trocar só por isso:
Se a role for igual a 0, ele vai retornar true, se não for, vai retornar false