Skip to content


Attributes in validations should be unique #7354

wants to merge 1 commit into from

2 participants


I see duplicated error messages while validations. It happens because of attribute was passed to validate_presence_of two times by different developers. It could be useful if ActiveModel will make attributes unique.

Ruby on Rails member

I particularly don't think that Rails should handle developer's mistakes of adding the same field twice to a list of attributes to be validated. If we (as developers) detect the problem (for instance, by seeing duplicated error messages), we can fix it in our code, if we change Rails to ignore the problem, we'll probably never notice the problem exists, and we'll continue doing it over and over.

Thanks for your contribution.

ps: please send new pull requests against the master branch, they'll be backported if needed (unless it's a specific bug that only happens there).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 15, 2012
  1. @saks

    validations should be uniq

    saks committed
2 activemodel/lib/active_model/validations/with.rb
@@ -4,7 +4,7 @@ module HelperMethods
def _merge_attributes(attr_names)
options = attr_names.extract_options!
- options.merge(:attributes => attr_names.flatten)
+ options.merge(:attributes => attr_names.flatten.uniq)
2 activemodel/test/cases/validations/presence_validation_test.rb
@@ -14,7 +14,7 @@ class PresenceValidationTest < ActiveModel::TestCase
def test_validate_presences
- Topic.validates_presence_of(:title, :content)
+ Topic.validates_presence_of(:title, :content, :content)
t =
assert t.invalid?
Something went wrong with that request. Please try again.