cancan - Fetch record based on role rails -
i using devise , cancan projects , works fine. there users table in database. there 3 types of role
->admin ->publishers ->players
now want fetch record users table expect admin's record.
i little confused how this.
if role string in user table:
scope :with_role, lambda{|role_name| where(:role => role_name) }
if user belongs_to role:
scope :with_role, lambda{|role_name| includes(:role).where(:roles => {:title => role_name}) }
and can fetch admins:
user.with_role('admin')
Comments
Post a Comment