Skip to content

Instantly share code, notes, and snippets.

@orafaelfragoso
Created March 20, 2014 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orafaelfragoso/9666425 to your computer and use it in GitHub Desktop.
Save orafaelfragoso/9666425 to your computer and use it in GitHub Desktop.
Member e Roles
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
class Role < ActiveRecord::Base
belongs_to :member
end
@lcezermf
Copy link

cara acho que isso:

def manager?
  (false if self.role == 0) || true
end

tu pode trocar só por isso:

def manager?
  self.role == 0
end

Se a role for igual a 0, ele vai retornar true, se não for, vai retornar false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment