Class: Address
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Address
- Defined in:
- app/models/polymorphic/address.rb
Overview
Copyright © 2008-2013 Michael Dvorkin and contributors.
Fat Free CRM is freely distributable under the terms of MIT license. See MIT-LICENSE file or www.opensource.org/licenses/mit-license.php
Schema Information
Table name: addresses
id :integer not null, primary key
street1 :string(255)
street2 :string(255)
city :string(64)
state :string(64)
zipcode :string(16)
country :string(64)
full_address :string(255)
address_type :string(16)
addressable_id :integer
addressable_type :string(255)
created_at :datetime
updated_at :datetime
deleted_at :datetime
Class Method Summary collapse
-
.reject_address(attributes) ⇒ Object
—————————————————————————- Ensure blank address records don’t get created.
Instance Method Summary collapse
-
#blank? ⇒ Boolean
Checks if the address is blank for both single and compound addresses.
Class Method Details
.reject_address(attributes) ⇒ Object
Ensure blank address records don’t get created. If we have a new record and
address is empty then return true otherwise return false so that _destroy
is processed (if applicable) and the record is removed.
Intended to be called as follows:
accepts_nested_attributes_for :business_address, :allow_destroy => true, :reject_if => proc {|attributes| Address.reject_address(attributes)}
51 52 53 54 55 56 |
# File 'app/models/polymorphic/address.rb', line 51 def self.reject_address(attributes) exists = attributes['id'].present? empty = %w(street1 street2 city state zipcode country full_address).map{|name| attributes[name].blank?}.all? attributes.merge!({:_destroy => 1}) if exists and empty return (!exists and empty) end |
Instance Method Details
#blank? ⇒ Boolean
Checks if the address is blank for both single and compound addresses.
37 38 39 40 41 42 43 |
# File 'app/models/polymorphic/address.rb', line 37 def blank? if Setting.compound_address %w(street1 street2 city state zipcode country).all? { |attr| self.send(attr).blank? } else self.full_address.blank? end end |