Created
February 12, 2020 00:58
-
-
Save sprite2005/40110aab59933d4e95c4b2e31829bf28 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 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