Sha256: 1bf1896c94b4785783295f932a450076d0dc68519e39361bb070c0e435433803

Contents?: true

Size: 1.29 KB

Versions: 6

Compression:

Stored size: 1.29 KB

Contents

module KktShoppe
  class Customer < ActiveRecord::Base

    self.table_name = "kkt_shoppe_customers"

    has_many :addresses, :dependent => :restrict_with_exception, :class_name => "KktShoppe::Address"

    has_many :orders, :dependent => :restrict_with_exception, :class_name => "KktShoppe::Order"

    # Validations
    validates :email, :presence => true, :uniqueness => true, :format => {:with => /\A\b[A-Z0-9\.\_\%\-\+]+@(?:[A-Z0-9\-]+\.)+[A-Z]{2,6}\b\z/i}
    validates :phone, :presence => true, :format => {:with => /\A[\d\ \-x\(\)]{7,}\z/}

    # All customers ordered by their ID desending
    scope :ordered, -> { order(:id => :desc)}

    # The name of the customer in the format of "Company (First Last)" or if they don't have
    # company specified, just "First Last".
    #
    # @return [String]
    def name
      company.blank? ? full_name : "#{company} (#{full_name})"
    end

    # The full name of the customer created by concatinting the first & last name
    #
    # @return [String]
    def full_name
      "#{first_name} #{last_name}"
    end

    def self.ransackable_attributes(auth_object = nil) 
      ["id", "first_name", "last_name", "company", "email", "phone", "mobile"] + _ransackers.keys
    end
  
    def self.ransackable_associations(auth_object = nil)
      []
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
kkt_shoppe-2.0.2 app/models/kkt_shoppe/customer.rb
kkt_shoppe-2.0.1 app/models/kkt_shoppe/customer.rb
kkt_shoppe-2.0.0 app/models/kkt_shoppe/customer.rb
kkt_shoppe-1.3.0 app/models/kkt_shoppe/customer.rb
kkt_shoppe-1.2.1 app/models/kkt_shoppe/customer.rb
kkt_shoppe-1.2.0 app/models/kkt_shoppe/customer.rb