Hello,
I'm pretty new to rails and it's the first time I'm actually using authlogic + acl9. I followed the default installation steps for both plugins.
So far everything works great, but I have trouble to find an elegant solution for this problem:
Let's say I have a model class called Products. When creating a new Product object I assign the current_user as the owner:
current_user.has_role! :owner, @product
I registered a second user and made sure that this part worked.
In the products controller I have an index method, simply returning all products:
def index
@products = Products.all
end
My question is: How do I call the find method on Products in order to get just those products where the current_user is the :owner? So I using the acl9 interface that would mean:
@product.accepts_role?(:owner, current_user)
One possibility probably would be to first retrieve all products and then create a new array with just the current_user ones. so maybe like this:
@products = []
products = Products.all
products.each do |p|
@products << p if p.accepts_role?(:owner, current_user)
end
This solution seems pretty wasteful. So what's the right way to do it?
Thanks everyone!