Skip to content

Instantly share code, notes, and snippets.

@JuarezLustosa
Created December 16, 2016 12:30
Show Gist options
  • Save JuarezLustosa/47d374468e132618266e0b9f9af8dbee to your computer and use it in GitHub Desktop.
Save JuarezLustosa/47d374468e132618266e0b9f9af8dbee to your computer and use it in GitHub Desktop.
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