I have the following associated models
class Enrollment < ActiveRecord::Base
has_many :addresses
end
class Address < ActiveRecord::Base
belongs_to :address_type
end
Currently I'm using the following (which I think is ugly) to filter out enrollment addresses of a certain address type.
class Enrollment < ActiveRecord::Base
def local_address
adds = []
addresses.each do |add|
adds << add if add.address_type.name == 'Local'
end
adds.last
end
end
Is there a way of using named scope of doing the same thing?