I am new to rails and this is the first time I am using authlogic + acl9. I followed the default installation steps for both plugins.
So far, everything is working fine, but it's hard for me to find an elegant solution to this problem:
Let's say I have a model class called Products. When creating a new Product object, I assign current_user as the owner:
current_user.has_role! :owner, @product
I registered a second user and made sure that this part works.
In the product controller, I have an index method just returning all products:
def index @products = Products.all end
My question is: how can I call the find method on Products to get only those products where current_user is: the owner? Therefore, I use the acl9 interface, which will mean:
@product.accepts_role?(:owner, current_user)
One possibility would probably be to first get all the products and then create a new array with only current_user tags. it can be like this:
@products = [] products = Products.all products.each do |p| @products << p if p.accepts_role?(:owner, current_user) end
This decision seems rather wasteful. So what is the right way to do this?
Thanks everyone!
source share