我想通过以下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
但它不起作用。有人可以解释一下吗?