我在使用 cancan 限制显示给特定用户组的数据时遇到问题。
我的用户有很多产品。并且产品有很多优惠券。
在我的 routes.rb 我有这个:
resources :products do
resources :vouchers
end
在能力.rb 中:
can [:create, :update, :read ], Voucher, :product => { :user_id => user.id }
在我的凭证控制器中:
def index
...
if params[:product_id]
@voucher = Voucher.find_all_by_product_id(params[:product_id])
end
...
end
最后,在我看来,我试图在与当前用户关联的产品组中显示优惠券列表。
例如:
http://localhost:3000/products/eef4e33116a7db/voucher
这列出了产品组中的优惠券,但是,所有用户都可以看到每个优惠券/产品。
我会假设我的能力是错误的。请帮忙 :)