I'm trying to create a method on a model (Note) that finds a subset of records, but banging my head against a brick wall. The code so far:
class Note belongs_to :person
def self.can_be_viewed find(:all, :conditions => ["notes.created_at <= ?", person.cutoff_date]) end ...
class Person has_many :notes
def cutoff_date ... end ...
Ultimately I want to be able to use @person.notes.can_be_viewed, but I'm getting an "undefined local variable or method `person' for #<Class:0x8ed10b8>" error. This isn't surprising - the can_be_viewed method is a class method, so has no way of accessing person.cutoff_date in the finder.
All I'm really trying to say here is: 1. A person has a cutoff date (this can vary according to who the logged-in user is, but that's irrelevant, although the cutoff_date method generates some SQL). 2. Notes can be viewed if they are created before their person's cutoff_date (note.person.cutoff_date).
I'd appreciate any thoughts on this.