Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #11456 (closed defect: fixed)

Opened 8 months ago

Last modified 8 months ago

[PATCH] validates_numericality_of does not replace option in custom message like in default message

Reported by: mdempfle Assigned to: core
Priority: normal Milestone: 2.x
Component: ActiveRecord Version: edge
Severity: normal Keywords:
Cc:

Description

When using e.g. validates_numericality_of :budget, :allow_nil=> true, :less_than=>1000000000, :message => "smaller than %d"

%d is not replaced in the custom message but it is on the default ruby message "must be less than %d"

this can be fixed by changing line

record.errors.add(attr_name, configuration[:message] (ActiveRecord::Errors.default_error_messages[option] % configuration[option])) unless raw_value.method(ALL_NUMERICALITY_CHECKS[option])[configuration[option]]

in validates_numericality_of (line 865 of Revision 9055)

to:

record.errors.add(attr_name, (configuration[:message] % configuration[option]) (ActiveRecord::Errors.default_error_messages[option] % configuration[option])) unless raw_value.method(ALL_NUMERICALITY_CHECKS[option])[configuration[option]]

hope this helps. /Michael

Attachments

fix_message_validates_numericality_of.diff (2.0 kB) - added by miloops on 03/28/08 16:36:37.

Change History

03/28/08 16:36:37 changed by miloops

  • attachment fix_message_validates_numericality_of.diff added.

03/28/08 16:39:34 changed by miloops

  • summary changed from validates_numericality_of does not replace option in custom message like in default message to [PATCH] validates_numericality_of does not replace option in custom message like in default message.

It's nice to have this option, i attach a patch with tests to add it, i think is more an enhancement than a bug, but still useful.

03/31/08 01:49:34 changed by bitsweat

  • status changed from new to closed.
  • resolution set to fixed.

(In [9158]) Add :message option to validates_numericality_of. Closes #11456 [miloops, mdempfle]