CanCan ::错误 - 可以吗?不能?调用不能与原始sql'can'定义一起使用

时间:2016-12-22 06:56:50

标签: ruby-on-rails cancan

ability.rb

@Override
public void onBackPressed(){
 super.onBackPressed();
    }

index.html.erb

can :destroy, Business, Business.where(id: user.auth_ids)

如果用户字段auth_ids:[]包含业务ID,我想访问删除按钮 但是我得到了这样的错误

<% if can? :destroy, @business %>
  <%= link_to 'delete', business_path(@business.id), method: :delete%>
<% end %>

任何人都可以告诉我导致问题的原因以及如何解决问题?

1 个答案:

答案 0 :(得分:0)

当语法不正确时,似乎会发生这种情况。试试hash with your condition

# ability.rb

can :destroy, Business, id: user.auth_ids

block condition with your scope

# ability.rb

can :destroy, Business, Business.where(id: user.auth_ids) do
  #... additional logic
end