Skip to content

Instantly share code, notes, and snippets.

@sprite2005
Created February 12, 2020 01:06
Show Gist options
  • Save sprite2005/e3d2f45d5dc82f5001832ba586158399 to your computer and use it in GitHub Desktop.
Save sprite2005/e3d2f45d5dc82f5001832ba586158399 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, reject_if: :reject_if_photo_limit_reached
validates_associated :photos
# validate :photo_limit
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