Skip to content

Instantly share code, notes, and snippets.

@px-amaac
Created October 18, 2013 09:40
Show Gist options
  • Save px-amaac/7039130 to your computer and use it in GitHub Desktop.
Save px-amaac/7039130 to your computer and use it in GitHub Desktop.
class Address < ActiveRecord::Base
before_save {|user| user.email = email.downcase}
has_one :color, through: :color_relationship
has_one :zip_code, through: :zip_code_relationship
has_one :zip_code_relationship, :dependent => :destroy
has_one :color_relationship, :dependent => :destroy
attr_accessor :code
attr_accessor :f_color
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :firstName, :lastName, presence: true
validates :email, presence: true, format: {with: VALID_EMAIL_REGEX }, uniqueness: {case_sensitive: false}
validates :code, presence: true, code: true
validates :f_color, presence: true, f_color: true
class ZipCode < ActiveRecord::Base
has_many :zip_code_relationships
end
class ZipCodeRelationship < ActiveRecord::Base
belongs_to :address
belongs_to :zip_code
validates :address_id, :zip_code_id, presence: true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment