7

I have a controller where I have

load_and_authorize_resource :product ,:through => :current_user

...

def set_user_product
  @user_product = User::Product.find_by_id(params[:id])
end

My ability.rb file contain

can :edit, User::Product do |product|
  product.try(:user) == user
end

Every thing looks ok but when I enter another user's product id in url I get

ActiveRecord::RecordNotFound in User::ProductsController#edit

Completed 404 Not Found in 23ms

ActiveRecord::RecordNotFound (Couldn't find User::Product with 'id'=<another_user_product_id> [WHERE `products`.`user` = ?]):

activerecord (4.2.0) lib/active_record/relation/finder_methods.rb:336:in `raise_record_not_found_exception!'

enter image description here

How can I resolve this error raised from cancan

Andrey Deineko
  • 51,333
  • 10
  • 112
  • 145
Braham Shakti
  • 1,408
  • 4
  • 22
  • 39

0 Answers0