Sha256: 5f998332df9f449ad7103918a3a9fb0648485161df59bc6bb91706df2270edbe

Contents?: true

Size: 987 Bytes

Versions: 16

Compression:

Stored size: 987 Bytes

Contents

module Piggybak 
  class Address < ActiveRecord::Base
    belongs_to :state
    belongs_to :country

    validates_presence_of :firstname
    validates_presence_of :lastname
    validates_presence_of :address1
    validates_presence_of :city
    validates_presence_of :state_id
    validates_presence_of :country_id
    validates_presence_of :zip

    after_initialize :set_default_country

    def set_default_country
      self.country ||= Country.find_by_abbr(Piggybak.config.default_country)
    end

    def admin_label
      address = "#{self.firstname} #{self.lastname}<br />"
      address += "#{self.address1}<br />"
      if self.address2 && self.address2 != ''
        address += "#{self.address2}<br />"
      end
      address += "#{self.city}, #{self.state_display} #{self.zip}<br />"
      address += "#{self.country.name}"
      address
    end
    alias :display :admin_label  

    def state_display
      self.state ? self.state.name : self.state_id
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
piggybak-0.4.12 app/models/piggybak/address.rb
piggybak-0.4.11 app/models/piggybak/address.rb
piggybak-0.4.10 app/models/piggybak/address.rb
piggybak-0.4.9 app/models/piggybak/address.rb
piggybak-0.4.8 app/models/piggybak/address.rb
piggybak-0.4.7.1 app/models/piggybak/address.rb
piggybak-0.4.7 app/models/piggybak/address.rb
piggybak-0.4.6 app/models/piggybak/address.rb
piggybak-0.4.5 app/models/piggybak/address.rb
piggybak-0.4.4 app/models/piggybak/address.rb
piggybak-0.4.3 app/models/piggybak/address.rb
piggybak-0.4.2 app/models/piggybak/address.rb
piggybak-0.4.1 app/models/piggybak/address.rb
piggybak-0.4.0 app/models/piggybak/address.rb
piggybak-0.3.2 app/models/piggybak/address.rb
piggybak-0.3.1 app/models/piggybak/address.rb