Hi everyone.
SCENARIO:
Given that a model called Edition has its community feature enabled
I want all Records under that Edition to validate for the community field
When the community feature is disabled, the community field will NOT be validated
Basically, I am trying to write a custom validation function at the ActiveRecord level, that will check if the parent edition has the proper true/false value.
But I am not sure the best way to handle this. My instinct is something like this, but I though I would get the communities' feedback:
class Record < ActiveRecord::Base
validate edition_has_communities?
private
def edition_has_communities?
if self.edition.communities_enabled
if community.blank?
errors.add(:community, "must be filled out for this Edition")
end
end
end
end
My concern is, that this method depends on the association with the Edition being defined prior to validation, and that may not always be the case. Would this be something that should be validated on the front end maybe?
Thoughts?