通过rails中的联接查询实现特定记录的cancan权限

时间:2015-02-05 12:21:28

标签: mysql ruby-on-rails activerecord cancan

我想通过以下rails活动记录查询为当前用户提供管理来自菜单表的特定记录的能力:

Menu.joins(location: :owner_associations).where('owner_associations.user_id' => current_user.id,'owner_associations.place_type'=>"Location")

我在我的ability.rb类中执行此操作:

@menu = Menu.joins(location: :owner_associations).where('owner_associations.user_id' => user.id,'owner_associations.place_type'=>"Location")
can :manage, @menu

并且在视图中我将其检查为:

<%@menu = Menu.joins(location: :owner_associations).where('owner_associations.user_id' => current_user.id,'owner_associations.place_type'=>"Location")%>
<% if can? :manage, @menu %>
   //display menu here

但它不起作用。有人可以解释一下吗?

0 个答案:

没有答案