Defect #2626
closedError during translation of the "is too short" and "is too long" messages
0%
Description
PROBLEM:
This class of message is causing ActionView::TemplateError translation value error ("too few arguments") and a resulting 500 HTTP error in 0.8.0.
REASON:
The cause is in the error_message_for() method of app/helpers/application_helper.rb--prior to the call to l() to obtain a localized msg, the msg Array is forcibly transformed into msg.first which is the String to display to the user.
This breaks the call to GLoc's l() method when the String has dynamically filled fields which used to follow the String in msg, but were stripped off. The actual error occurs in GLoc's internal _l() method.
GLoc is present at vendor/plugins/gloc-1.1.0/
MY FIX:
Repair application_helper.rb to not do that transformation. In fact, fix it so that if msg is just String, it is turned into an Array with just the String (opposite of what is there) and call l(*msg) instead of l(msg).
PATCH (changes 2 lines):
--- broken/app/helpers/application_helper.rb 2009-01-26 09:49:24.000000000 -0600 +++ app/helpers/application_helper.rb 2009-01-30 10:17:35.000000000 -0600 @@ -524,11 +525,12 @@ full_messages = [] object.errors.each do |attr, msg| next if msg.nil? - msg = msg.first if msg.is_a? Array + msg = [msg] if(msg.is_a?(String)) if attr == "base" full_messages << l(msg) else - full_messages << "« " + (l_has_string?("field_" + attr) ? l("field_" + attr) : object.class.human_attribute_name(attr)) + " » " + l(msg) unless attr == "custom_values" + full_messages << "« " + (l_has_string?("field_" + attr) ? l("field_" + attr) : object.class.human_attribute_name(attr)) + " » " + l(*msg) unless attr == "custom_values" end end # retrieve custom values error messages
My env:
mysql-5.0.67 rails (2.1.2) ruby 1.8.7 (2008-08-08 patchlevel 71) [x86_64-linux] redmine 0.8.0
Files
Related issues