Why doesn't Rails' “errors.full_messages” replace attribute and message variables?

后端 未结 8 1668
小鲜肉
小鲜肉 2020-12-09 16:22

Having a strange problem with a rails model I just created.

Here are my validations:

validates_presence_of :from_name, :message => \'Please provid         


        
相关标签:
8条回答
  • 2020-12-09 17:12

    Here's my complete config/locales/en.yml that solves the attribute, message, count, and model issues. I got this from the RoR docs here: http://guides.rubyonrails.org/i18n.html

    en: activerecord: errors: full_messages: format: "%{attribute} %{message}" template: header: one: "1 error prohibited this %{model} from being saved" other: "%{count} errors prohibited this %{model} from being saved"

    0 讨论(0)
  • 2020-12-09 17:17

    I fixed locally by removing i18n-0.5.0.

    experimenting with i18n-0.4.0 yields (while returning the correctly interpolated string):

    The {{key}} interpolation syntax in I18n messages is deprecated. Please use %{key} instead.
    /usr/lib/ruby/gems/1.8/gems/i18n-0.4.0/lib/i18n/backend/base.rb:160:in `interpolate_without_deprecated_syntax'
    /usr/lib/ruby/gems/1.8/gems/i18n-0.4.0/lib/i18n/backend/base.rb:155:in `gsub'
    /usr/lib/ruby/gems/1.8/gems/i18n-0.4.0/lib/i18n/backend/base.rb:155:in `interpolate_without_deprecated_syntax'
    /usr/lib/ruby/gems/1.8/gems/i18n-0.4.0/lib/i18n/backend/base.rb:188:in `preserve_encoding'
    /usr/lib/ruby/gems/1.8/gems/i18n-0.4.0/lib/i18n/backend/base.rb:154:in `interpolate_without_deprecated_syntax'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/i18n_interpolation_deprecation.rb:21:in `interpolate'
    /usr/lib/ruby/gems/1.8/gems/i18n-0.4.0/lib/i18n/backend/base.rb:48:in `translate'
    /usr/lib/ruby/gems/1.8/gems/i18n-0.4.0/lib/i18n.rb:152:in `translate'
    /usr/lib/ruby/gems/1.8/gems/i18n-0.4.0/lib/i18n/backend/base.rb:119:in `resolve'
    /usr/lib/ruby/gems/1.8/gems/i18n-0.4.0/lib/i18n/backend/base.rb:104:in `default'
    /usr/lib/ruby/gems/1.8/gems/i18n-0.4.0/lib/i18n/backend/base.rb:103:in `each'
    /usr/lib/ruby/gems/1.8/gems/i18n-0.4.0/lib/i18n/backend/base.rb:103:in `default'
    /usr/lib/ruby/gems/1.8/gems/i18n-0.4.0/lib/i18n/backend/base.rb:41:in `translate'
    /usr/lib/ruby/gems/1.8/gems/i18n-0.4.0/lib/i18n.rb:152:in `translate'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/validations.rb:78:in `generate_message'
    

    I guess 0.5.0 turns up the pain by outputting non-interpolated strings.


    i18n is required by activesupport, so the way I got around loading the most recent version (0.5.0) is:

    in config/preinitializer.rb ('secret' lifecycle hook that loads before activesupport):

    require 'rubygems'
    begin
      gem 'i18n', "~> 0.4.0"
    rescue LoadError
      # no biggie, optional anyway
    end
    
    0 讨论(0)
提交回复
热议问题