Sha256: eaa2eea69df286161a53abc3eef78c50b22dc096ec79fb1aba2692588db4bd01

Contents?: true

Size: 1.29 KB

Versions: 3

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

3 entries across 3 versions & 1 rubygems

Version Path
kkt_shoppe-1.1.2 app/models/kkt_shoppe/customer.rb
kkt_shoppe-1.1.1 app/models/kkt_shoppe/customer.rb
kkt_shoppe-1.1.0 app/models/kkt_shoppe/customer.rb