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

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -