Wrap conditions around many find requests

Dear all,

Is it possible to declare Active Record ‘find’ conditions and have these
‘:conditions’ apply to numerous find queries on a table without having
to re-declare the conditions on every line where you have a find?

As an example, suppose you have a table of records of users and
throughout a controller you only want to query records of people who are
not ‘administrators’

A few months ago, when I read through a draft PDF of Agile Web
Development with Rails 2nd ed, I seem to remember reading something like
this…I think it even said you could declare a condition in an ‘around
filter’ and have it apply to all ‘find’ calls within filtered actions.
But for the life of me, if it was there I can’t find it in the final
version.

Thanks, Nat

Nat,

I think with_scope() is what you’re looking for.


Zack C.
http://depixelate.com