【发布时间】:2013-02-17 08:52:41
【问题描述】:
在 User 属于Organization 的应用程序上工作。 Organization has_and_belongs_to_many Products,虽然是 organizations_products 表。
我想要一个具有特定角色的User 能够为他们的Organization 管理产品。在ability.rb:
def initialize(user)
# ...snip unrelated stuff
elsif user.is_manager?
can :manage, Product, do |product|
user.organization.products.include?(product)
end
这描述了我想要做什么,但它在产品控制器中引发了一个异常:
def index
@products = Product.accessible_by(current_ability)
end
因为acessible_by can't be used with blocks 在能力定义中。如何以兼容accessible_by的方式编写此功能?
【问题讨论】: