Skip to content

Instantly share code, notes, and snippets.

@sprite2005
Created February 12, 2020 00:58
Show Gist options
  • Save sprite2005/40110aab59933d4e95c4b2e31829bf28 to your computer and use it in GitHub Desktop.
Save sprite2005/40110aab59933d4e95c4b2e31829bf28 to your computer and use it in GitHub Desktop.
class User < ApplicationRecord
validates :sc_external_id, presence: true, uniqueness: true, length: { minimum: 10 }
has_one :profile, dependent: :destroy
has_many :photos, dependent: :destroy
accepts_nested_attributes_for :photos, allow_destroy: true
validates_associated :photos
validate :photo_limit
private
def photo_limit
errors.add(:base, "You have reached the maximum number of photos") if photos.count > 6
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment