Forum: Ruby on Rails Wrap conditions around many find requests

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
8a3abcfeae74fa0ea68bb23ef0501511?d=identicon&s=25 Nathaniel (Guest)
on 2007-03-17 00:16
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

Thanks, Nat
C4dc94c893471878a105761a9207f29b?d=identicon&s=25 Zack Chandler (Guest)
on 2007-03-17 00:44
(Received via mailing list)

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

Zack Chandler
This topic is locked and can not be replied to.