Created
December 16, 2016 12:30
-
-
Save JuarezLustosa/47d374468e132618266e0b9f9af8dbee 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
In addition, here is the code I used for the solution Chris suggested, for anyone interested. | |
# /models/concerns/location_validations.rb | |
module LocationValidations | |
extend ActiveSupport::Concern | |
included do | |
validates :name, presence: true | |
validates :address, presence: true | |
validates :state, presence: true | |
validates :zipcode, presence: true | |
validates :country, presence: true | |
end | |
end | |
# models/restaurant.rb | |
class Restaurant < ApplicationRecord | |
has_many :branches | |
has_and_belongs_to_many :users | |
validates :phone, presence: true | |
validates :email, presence: true | |
include LocationValidations | |
end | |
# models/branch.rb | |
class Branch < ApplicationRecord | |
belongs_to :restaurant | |
validates :resaurant_id, presence: true | |
include LocationValidations | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment