docbrown/app/models/custom_profile_field.rb
Michael Kohl 4ae59b56e3
Add custom profile fields (#10202)
* Add custom_profile_fields table

* Add CustomProfileField model and refactor

* Remove trailing whitespace

* Stop ignoring removed column

* Add explanatory comment

* Update service object

* Fix bug in service object

* Refactor and fix specs

* Increase limit from 3 to 5

* Update comment to reflect code changes
2020-09-09 14:37:15 +00:00

16 lines
378 B
Ruby

class CustomProfileField < ApplicationRecord
include ActsAsProfileField
belongs_to :profile
validate :validate_maximum_count
private
# We allow a maximum of 5 custom profile fields per user
def validate_maximum_count
return if profile.custom_profile_fields.count < 5
errors.add(:profile_id, "maximum number of custom profile fields exceeded")
end
end