当前位置: 动力学知识库 > 问答 > 编程问答 >

mysql - implementing cancan permission for specific records through joins query in rails

问题描述:

I want to give current user ability to manage specific records coming from menus table through the following rails active record query:

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

I am doing this in my ability.rb class:

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

can :manage, @menu

and in view i am checking for this as :

<%@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

but its not working. Can somebody explain?

分享给朋友:
您可能感兴趣的文章:
随机阅读: