我有一个控制器,我有
load_and_authorize_resource :product ,:through => :current_user
...
def set_user_product
@user_product = User::Product.find_by_id(params[:id])
end
我的ability.rb
文件包含
can :edit, User::Product do |product|
product.try(:user) == user
end
每件事看起来都不错但是当我在url中输入另一个用户的产品ID时,我得到了
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:在`raise_record_not_found_exception!'
如何解决从cancan
引发的此错误