tyb*_*103 22 ruby validation activerecord ruby-on-rails internationalization
我刚刚创建的rails模型出现了一个奇怪的问题.
以下是我的验证:
validates_presence_of :from_name, :message => 'Please provide a from name.'
validates_presence_of :from_email
validates_presence_of :giftition_plan_id
Run Code Online (Sandbox Code Playgroud)
我在使用errors.full_messages和使用时遇到了问题f.error_messages:
g = Giftition.create
g.errors.first
=> ["from_name", "Please provide a from name."]
>> g.errors.full_messages
=> ["{{attribute}} {{message}}", "{{attribute}} {{message}}", "{{attribute}} {{message}}"]
Run Code Online (Sandbox Code Playgroud)
我刚刚开始"{{attribute}} {{message}}".有任何想法吗?
更新:我已经卸载了rails 3以及随之安装的所有gem,这使问题消失了.虽然这不是一个修复...我仍然希望安装rails 3.
更新:听起来像升级到2.3.9修复了问题.不幸的是,我现在已经放弃了,但将来的某个时候我会尝试.
小智 12
我遇到了这个问题以及我继承的旧2.3.5 Rails应用程序.我安装了5.0版本的i18n gem.我看到它需要%{}语法.在config/locales/en.yml中执行此操作可以解决问题:
en:
activerecord:
errors:
full_messages:
format: "%{attribute} %{message}"
Run Code Online (Sandbox Code Playgroud)
升级到版本rails 2.3.9修复了此问题
gem install -v 2.3.9 rails --include-dependencies
Run Code Online (Sandbox Code Playgroud)
编辑:
您还需要编辑config\environment.rb文件以更改RAILS_GEM_VERSION.
RAILS_GEM_VERSION = '2.3.9'
Run Code Online (Sandbox Code Playgroud)
编辑#2:
我应该注意,版本2.3.9不是2.3.X分支的最新版本,您应该升级可用的最新版本.