I am using Rails 3, and building an app in which a user can put objects to be rented. For each object, he can decide:
- the object can be rented by the entire world (potentially) or not (object access is restricted)
- the object can only be rented by my friends (in the app, via a
has_many friends, :through => friendship
association) - the object can be rented by members of the following groups (then the user selects either all the groups he belongs to, or a subset of these)
My question is how to display the list of objects a current_user can see ? I see two options, and I would like to know which is the best one or if they are equivalent:
1) In the object controller, build the collection of the objects a user can see (@objects = Object.can_see(current_user)
) and then pass this to the index view and display the whole list
2) In the controller, collect ALL objects (@objects = Object.all
), pass this to the index view, and in the view, for each object, conduct a serie of test to determine if the object should be displayed or not.