Sha256: faba120cc6c6cd5fdc32e0db5c5820e10a811742049b0de30a85988c86e0d24b
Contents?: true
Size: 1.35 KB
Versions: 5
Compression:
Stored size: 1.35 KB
Contents
module Shoppe class Address < ActiveRecord::Base # An array of all the available types for an address TYPES = ["billing", "delivery"] # Set the table name self.table_name = "shoppe_addresses" # The customer which this address should be linked to # # @return [Shoppe::Customer] belongs_to :customer, :class_name => "Shoppe::Customer" # The order which this address should be linked to # # @return [Shoppe::Order] belongs_to :order, :class_name => "Shoppe::Order" # The country which this address should be linked to # # @return [Shoppe::Country] belongs_to :country, :class_name => "Shoppe::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
5 entries across 5 versions & 2 rubygems