I’m wondering if there is a way to set a scope on a model class for the rest of a request? I.e. I want to scope down some results, but I want to do it without the main restful controller knowing (perhaps in a before_filter injected into the controller).
Contacts.scope = { :conditions => {:public => true} } if ladeda
then later on
Contacts.all
should return the contacts with the scope. That is just pretend code, does anyone know if this is possible?
Cheers,
Brendon
Here’s how I would do it:
I’m moving the decision to use a scope or not to a helper method. Alternatively, you could move the helper method to the Contact model itself, such as this: