ruby on rails - NameError when calling method in CanCan's Ability Class -
i'm using cancan role-based admin-system in application building. sort of template webshops, admin can have different role in each webshop he/she has access to. example: in webshop 1 moderator, , in webshop 2 editor.
so need in cancan's ability class check kind of role current user has in current shop (current_shop). wrote this:
class ability include cancan::ability def initialize(admin) if admin.supervise?(current_shop, controller_gsub) can :manage, :all elsif admin.manage?(current_shop, controller_gsub) can :manage, :all elsif admin.access?(current_shop, controller_gsub) can :read, :all end end end the problem can't seem call current_shop method ability class, because error:
undefined local variable or method `current_shop' #<ability:0x104df38b0> does know how go this? thanx in advance!
actually can't access of controller methods ability class. business logic? admin can manage every single thing if supervisor current_shop? or can manage things, manages shop?
then nice have smth like:
class ability include cancan::ability def initialize(admin) can :manage, :all |obj| admin.supervise?(obj.shop) || admin.manage?(obj.shop) end can :read, :all |obj| admin.access?(obj.shop) end end end ps i'm not quite sure block work :all, , it's not quite logical call .shop on unknown class, that's show way, it's easy enough list models used
Comments
Post a Comment