Created
February 12, 2020 01:06
-
-
Save sprite2005/8ff110a2ee73a5ecb77ac1a39ab8c4d4 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, reject_if: :reject_if_photo_limit_reached | |
validates_associated :photos | |
private | |
def reject_if_photo_limit_reached | |
if photos.count > 6 | |
true | |
else | |
false | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment