I am trying to make a custom validator for uniqueness. The following example does not work for some reason:
validates :language_id, uniqueness: { scope: :country_id}, if: :no_detail?
validates :language_id, uniqueness: { scope: [:country_id,:city_id, :province_id]}, if: :detail?
def no_detail?
if city_id.blank? && province_id.blank?
return true
else
return false
end
end
def detail?
return !no_detail?
end
The error I am getting is that there are duplicate language_ids when I create a new data entry.