Sha256: bda94bd8b1e526e40f6ee65cf7a36b9b01aec3e9fab65d5253d9469e28914beb
Contents?: true
Size: 1.01 KB
Versions: 1
Compression:
Stored size: 1.01 KB
Contents
# # Simply extracted some code to clean up model. # I'd like to do this to all of the really big classes # but let's see how this goes first. # module StudySubjectAddresses def self.included(base) # Must delay the calls to these ActiveRecord methods # or it will raise many "undefined method"s. base.class_eval do has_many :addressings has_many :addresses, :through => :addressings accepts_nested_attributes_for :addressings, :reject_if => proc { |attrs| !attrs[:address_required] && attrs[:address_attributes][:line_1].blank? && attrs[:address_attributes][:line_2].blank? && attrs[:address_attributes][:unit].blank? && attrs[:address_attributes][:city].blank? && attrs[:address_attributes][:zip].blank? && attrs[:address_attributes][:county].blank? } # Returns number of addresses with # address_type.key == 'residence' def residence_addresses_count addresses.count(:conditions => { :address_type_id => AddressType['residence'].id }) end end # class_eval end # included end # StudySubjectAddresses
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ccls-ccls_engine-3.11.0 | app/models/study_subject_addresses.rb |