ruby on rails - Finding a user is Admin or Not with Decalarative Authorization -
i have implemented declarative authorization in blog app. have 3 layouts each admin, authenticated user , guest user. need check type of user using app @ particular time. have user model, role model , assignment model.
user.rb
class user < activerecord::base attr_accessible :login, :email, :password, :password_confirmation, :role_ids has_many :articles has_many :comments has_many :assignments has_many :roles, :through => :assignments def role_symbols roles.map |role| role.name.underscore.to_sym end end acts_as_authentic |c| c.login_field = :login end def deliver_password_reset_instructions! reset_perishable_token! notifier.deliver_password_reset_instructions(self) end end assignment.rb
class assignment < activerecord::base belongs_to :user belongs_to :role end role.rb
class role < activerecord::base attr_accessible :name has_many :assignments has_many :users, :through => :assignments end any solution?
you simplify structure gem: https://github.com/platform45/easy_roles follow instructions on github , modify models described there. easy, few steps. need user model, , that´s it!
additionally reccomend cancan gem (https://github.com/ryanb/cancan).
easy_roles , cancan combination define roles , permissions quite easily!
Comments
Post a Comment