Having a strange problem with a rails model I just created.
Here are my validations:
validates_presence_of :from_name, :message => 'Please provide a from name.'
validates_presence_of :from_email
validates_presence_of :giftition_plan_id
I'm having issues using errors.full_messages
as well as f.error_messages
in my form:
g = Giftition.create
g.errors.first
=> ["from_name", "Please provide a from name."]
>> g.errors.full_messages
=> ["{{attribute}} {{message}}", "{{attribute}} {{message}}", "{{attribute}} {{message}}"]
I'm just getting "{{attribute}} {{message}}"
. Any ideas?
UPDATE: I've uninstalled rails 3 and all the gems that were installed with it and that made the problem go away. It's not a fix though... I would still like to have rails 3 installed.
UPDATE: Sounds like upgrading to 2.3.9 fixes the problem. Unfortunately, I've given up for now, but sometime in the future I will try that.
I ran into this problem as well with an old 2.3.5 Rails app that I inherited. I had the 5.0 version of the i18n gem installed. I saw that it needs the %{} syntax. Doing this in config/locales/en.yml did the trick:
en:
activerecord:
errors:
full_messages:
format: "%{attribute} %{message}"
Upgrading to Version rails 2.3.9 fixes this problem
gem install -v 2.3.9 rails --include-dependencies
EDIT:
You also need to edit the config\environment.rb
file to change the RAILS_GEM_VERSION
.
RAILS_GEM_VERSION = '2.3.9'
EDIT #2:
I should note that version 2.3.9 is not the latest version of the 2.3.X branch, and you should upgrade the the latest version available.
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
so i keep seeing upgrading rails as the solution to this
... or you can simply downgrade i18n to version 0.4
as outlined in this post
getting {{attribute}} {{message}} in RoR views
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With