Vincent Ritter

I worried how best to avoid duplicate emails for 'attendees' for a logged in user but allow that same email to be used for other attendees tied to other users (but at the same time being unique to that user_id).

Lucky for me, Rails has that baked in with 'scope'. Pretty awesome!

validates :email, presence: true, length: {maximum: 255}, format: {with: VALID_EMAIL_REGEX}, uniqueness: { case_sensitive: false, scope: :user_id }
Close