Using Rails 2.3.4, Ruby 1.8.7.
I have an ActiveRecord validation where I want to include the user's input in the error message. The simplified version of I'm doing something like this:
record.errors.add attr, "'#{calculated_value}' is not valid.'
Where calculated_value
is a portion of the user's input of a larger value.
I've found that if the user enters values that contain certain characters, odd things can happen. If calculated_value
contains %s
, %s
gets replaced by the full value the user entered. If calculated_value
contains ..
, I got:
ArgumentError - interning empty string from /var/lib/gems/1.8/gems/activesupport-2.3.4/lib/active_support/vendor/i18n-0.1.3/lib/i18n.rb:196:in `to_sym'.
I would like to know how I can disable the functionality or how I can escape these values. I tried escaping %s
to %%s
, sprintf-style, but that doesn't work.