gettext 2.0.4 and rails 2.3.4


Rails 2.3.4 broke gettext_activerecord 2.0.4

Well I did not test other gems of the mutoh gettext set of libraries but here is the gulty code that breaks rails.
Since Activerecord::Errors changed its implementation a bit, an error like this is raised :

NoMethodError: undefined method `gsub' for #<ActiveRecord::Error:0x00000002919738>
        from /home/hallelujah/Jail/lib/ruby/gems/1.9.1/gems/gettext_activerecord-2.0.4/lib/gettext_activerecord/validations.rb:165:in `localize_error_message'
        from /home/hallelujah/Jail/lib/ruby/gems/1.9.1/gems/gettext_activerecord-2.0.4/lib/gettext_activerecord/validations.rb:112:in `block (2 levels) in each_with_gettext_activerecord'
        from /home/hallelujah/Jail/lib/ruby/gems/1.9.1/gems/gettext_activerecord-2.0.4/lib/gettext_activerecord/validations.rb:112:in `each'
        from /home/hallelujah/Jail/lib/ruby/gems/1.9.1/gems/gettext_activerecord-2.0.4/lib/gettext_activerecord/validations.rb:112:in `block in each_with_gettext_activerecord'
        from /home/hallelujah/Jail/lib/ruby/gems/1.9.1/gems/gettext_activerecord-2.0.4/lib/gettext_activerecord/validations.rb:112:in `each_key'
        from /home/hallelujah/Jail/lib/ruby/gems/1.9.1/gems/gettext_activerecord-2.0.4/lib/gettext_activerecord/validations.rb:112:in `each_with_gettext_activerecord'

You can add this piece of code after your gems and rails are loaded (e.g at the bottom of config/environment.rb )

module ActiveRecord
  class Errors
    def localize_error_message_with_patch(attr,obj, append_field)
      obj = obj.respond_to?(:message) ? obj.message : obj
      localize_error_message_without_patch(attr,obj,append_field)
    end
    alias_method_chain :localize_error_message, :patch
  end
end

I think I will patch gettext_activerecord and the muto gettext set of library to fit in rails 2.3.4
Maybe I may keep an eye on Rails 3.0 development.

, , , , , , , , , , ,

  1. #1 by Hallelujah on October 26, 2009 - 15:37

    The patch was integrated.
    Thanks mutoh!

    If you want to check my git repository : http://github.com/hallelujah/gettext_activerecord

(will not be published)