Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix another regression due to the inclusion of ActiveRecord::Error.

If a string is supplied to :default, it should not be used a
translation key (we already have :message for that).
[#3564 status:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
  • Loading branch information...
commit 1c3711b21b5c80343a51e19504552b3f6c34ac73 1 parent b1bbf90
@josevalim josevalim authored josh committed
View
2  activerecord/lib/active_record/validations.rb
@@ -158,7 +158,7 @@ def add_to_base(msg)
# If +message+ is a Symbol, it will be translated, using the appropriate scope (see translate_error).
#
def add(attribute, message = nil, options = {})
- options[:message] = options.delete(:default) if options.has_key?(:default)
+ options[:message] = options.delete(:default) if options[:default].is_a?(Symbol)
error, message = message, nil if message.is_a?(Error)
@errors[attribute.to_s] ||= []
View
6 activerecord/test/cases/validations_i18n_test.rb
@@ -521,6 +521,12 @@ def assert_full_message(message, *args)
assert_equal message, ActiveRecord::Error.new(@reply, *args).full_message
end
+ test ":default is only given to message if a symbol is supplied" do
+ store_translations(:errors => { :messages => { :"foo bar" => "You fooed: {{value}}." } })
+ @reply.errors.add(:title, :inexistent, :default => "foo bar")
+ assert_equal "foo bar", @reply.errors[:title]
+ end
+
test "#generate_message passes the model attribute value for interpolation" do
store_translations(:errors => { :messages => { :foo => "You fooed: {{value}}." } })
@reply.title = "da title"
Please sign in to comment.
Something went wrong with that request. Please try again.