ruby on rails - CanCan not filtering @products in Index -
i working on rails 3.2 application devise , cancan.
my user model user, , want restrict access product resource ones created user. relevant code snippets:
app/models/ability.rb
class ability include cancan::ability def initialize(user) if user can :manage, product, user_id: user.id end end end
app/controller/products_controller.rb
class productscontroller < applicationcontroller load_and_authorize_resource .. end
config/routes.rb
... devise_for :products resources :products resources :sizes end ...
everything working expected: users cannot see, edit, etc... products not created them. problem if user access product index @ /products all products visible.
how can filter relevant products in index page?
i have googling around, , try authorize! :index, ability
in index action can :index, product, user_id: user.id
, user cannot access @ @ index page.
any appreciated.
this not authorization issue. instead should scope query, in index action product controller. eg this:
class productscontroller < applicationcontroller def index @products = current_user.products end end
Comments
Post a Comment