Skip to content

Commit

Permalink
Use activerecord.errors.format as in Rails 2.3.5.
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Jan 2, 2010
1 parent 5fdd0e8 commit 7cc0a4c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
6 changes: 3 additions & 3 deletions activemodel/lib/active_model/errors.rb
Expand Up @@ -105,11 +105,11 @@ def full_messages
else
attr_name = attribute.to_s.gsub('.', '_').humanize
attr_name = @base.class.human_attribute_name(attribute, :default => attr_name)
options = { :default => ' ', :scope => @base.class.i18n_scope }
prefix = attr_name + I18n.t(:"errors.format.separator", options)
options = { :default => "{{attribute}} {{message}}", :attribute => attr_name,
:scope => @base.class.i18n_scope }

messages.each do |m|
full_messages << "#{prefix}#{m}"
full_messages << I18n.t(:"errors.format", options.merge(:message => m))
end
end
end
Expand Down
3 changes: 3 additions & 0 deletions activemodel/lib/active_model/locale/en.yml
@@ -1,6 +1,9 @@
en:
activemodel:
errors:
# model.errors.full_messages format.
format: "{{attribute}} {{message}}"

# The values :model, :attribute and :value are always available for interpolation
# The value :count is available when applicable. Can be used for pluralization.
messages:
Expand Down
6 changes: 6 additions & 0 deletions activemodel/test/cases/validations/i18n_validation_test.rb
Expand Up @@ -61,6 +61,12 @@ def test_errors_full_messages_translates_human_attribute_name_for_model_attribut
@person.errors.full_messages
end

def test_errors_full_messages_uses_format
I18n.backend.store_translations('en', :activemodel => {:errors => {:format => "Field {{attribute}} {{message}}"}})
@person.errors.add('name', 'empty')
assert_equal ["Field Name empty"], @person.errors.full_messages
end

# ActiveRecord::Validations
# validates_confirmation_of w/ mocha
def test_validates_confirmation_of_generates_message
Expand Down
3 changes: 3 additions & 0 deletions activerecord/lib/active_record/locale/en.yml
@@ -1,6 +1,9 @@
en:
activerecord:
errors:
# model.errors.full_messages format.
format: "{{attribute}} {{message}}"

# The values :model, :attribute and :value are always available for interpolation
# The value :count is available when applicable. Can be used for pluralization.
messages:
Expand Down

0 comments on commit 7cc0a4c

Please sign in to comment.