I am working with extensions to has_many associations, and I want to
a finder method that is conditional on the attributes of the object
association I’m working with.
So, to use the example from the Agile Web D.: the authors show
pg 340 in the second edition how to pass an argument to a finder method.
I want to know if it’s possible to instead have the finder method look
attributes of the object on which the finder method is ultimately being
executed (here, user) to determine the conditions.
has_many :articles, :through => :readings do
def rated_at_or_above(rating) # this is the finder
method in AWD – works fine
find :all, :conditions => [‘rating >= ?’, rating]
def rated_at_or_above_threshold # but can I do
like this? (doesn’t work)
find :all, :conditions => [‘rating >= ?’, user.threshold] #
NoMethodError: undefined method user for Article:class
How would I implement this? As the error suggests, the problem is that
article doesn’t know who its user is. So how can I pass that information
this method, given that it’s nested inside of this association?
(Btw, I tried to post this yesterday but it has not appeared, and
msg suggested that posts made from the Google G. page get lost
– sorry if this is double-posted.)