Working on an app where a User belongs_to an Organization. An Organization has_and_belongs_to_many Products, though an organizations_products table.
I want a User with a particular role to be able to manage Products for their Organization. In ability.rb:
def initialize(user)
# ...snip unrelated stuff
elsif user.is_manager?
can :manage, Product, do |product|
user.organization.products.include?(product)
end
This describes what I want to do but it raises an exception in the products controller:
def index
@products = Product.accessible_by(current_ability)
end
because acessible_by can't be used with blocks in ability definitions. How can I write this ability in a way that is compatible with accessible_by?