Sha256: 870a594c82a6f176a396c6498e46497fec60c6db3f50ef623e779181a8b62881
Contents?: true
Size: 1.37 KB
Versions: 9
Compression:
Stored size: 1.37 KB
Contents
module KktShoppe class Address < ActiveRecord::Base # An array of all the available types for an address TYPES = ["billing", "delivery"] # Set the table name self.table_name = "kkt_shoppe_addresses" # The customer which this address should be linked to # # @return [KktShoppe::Customer] belongs_to :customer, :class_name => "KktShoppe::Customer" # The order which this address should be linked to # # @return [KktShoppe::Order] belongs_to :order, :class_name => "KktShoppe::Order" # The country which this address should be linked to # # @return [KktShoppe::Country] belongs_to :country, :class_name => "KktShoppe::Country" # Validations validates :address_type, :presence => true, :inclusion => {:in => TYPES} validates :address1, :presence => true validates :address3, :presence => true validates :address4, :presence => true validates :postcode, :presence => true validates :country, :presence => true # All addresses ordered by their id asending scope :ordered, -> { order(:id => :desc)} scope :default, -> { where(default: true)} scope :billing, -> { where(address_type: "billing")} scope :delivery, -> { where(address_type: "delivery")} def full_address [address1, address2, address3, address4, postcode, country.try(:name)].join(", ") end end end
Version data entries
9 entries across 9 versions & 1 rubygems