Unable to access model using cancan gem in rails

111 views Asked by At

I am using Spree to build an e-commerce application.I have created one model Offer(Spree::Offer) . I have created one role seller,and I am trying to give seller access to view,update and manage this model(Offer) in the admin panel using the following code

if user.respond_to?(:has_spree_role?) and user.has_spree_role?('supplier') > can :manage,Offer

But when I login as seller,I am unable to see Offers Tab in the Admin Panel But,when I login as admin ,I am able to see Offers Tab.Admin has following access

can :manage,:all

I am new to rails, Should I do anything prior, to get the desired result

1

There are 1 answers

0
milind phirake On BEST ANSWER

You need to define the ability like this as the offer model is under the spree module then and then you can access the Spree::Offer recourse.

if user.respond_to?(:has_spree_role?) and user.has_spree_role?('supplier') 
  can :manage, Spree::Offer
end