Created
October 18, 2013 09:40
-
-
Save px-amaac/7039130 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ZipCode < ActiveRecord::Base | |
has_many :zip_code_relationships | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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