Ruby on rails RoR=>;奇怪的验证消息

Ruby on rails RoR=>;奇怪的验证消息,ruby-on-rails,forms,validation,Ruby On Rails,Forms,Validation,我是rails的新手,今天我使用validate创建了我的第一个web应用程序,我在模型中加入了以下几行代码: class ClientWorkout < ActiveRecord::Base validates_numericality_of :paid_amount validates_presence_of :client_name end (示例显示了当表单的两个参数错误时会发生什么,但在每种情况下都会发生这种情况) 它无法用实际值替换“计数、模型、属性和消息”。 谁

我是rails的新手,今天我使用validate创建了我的第一个web应用程序,我在模型中加入了以下几行代码:

class ClientWorkout < ActiveRecord::Base

  validates_numericality_of :paid_amount
  validates_presence_of :client_name

end
(示例显示了当表单的两个参数错误时会发生什么,但在每种情况下都会发生这种情况)
它无法用实际值替换“计数、模型、属性和消息”。 谁都知道发生了什么事?
我使用Ror 2.3.8和rails 1.8.7,rails在2.3中引入了内置国际化。您的问题是一个已知的bug,它是rails和i18nGem的一些组合。如果您有i18ngem版本0.5.0,请尝试降级到0.4.2。如果您使用的是系统宝石:

sudo gem uninstall i18n
sudo gem install i18n -v 0.4.2

如果使用RVM管理gems,则不需要
sudo
命令。

Rails在2.3版中引入了内置国际化。您的问题是一个已知的bug,它是rails和i18nGem的一些组合。如果您有i18ngem版本0.5.0,请尝试降级到0.4.2。如果您使用的是系统宝石:

sudo gem uninstall i18n
sudo gem install i18n -v 0.4.2

如果您使用RVM管理gems,则不需要使用
sudo
命令。

如果您对更改i18n版本不感兴趣,可以执行以下操作 在
config/locales/en.ym

如果
en:
已可用,请从ActiveRecord复制并粘贴

之后,停止服务器并再次启动,以正确显示错误消息

en:
  activerecord: 
    errors: 
      full_messages: 
        format: "%{attribute} %{message}"
      messages:
        inclusion: "is not included in the list"
        exclusion: "is reserved"
        invalid: "is invalid"
        confirmation: "doesn't match %{attribute}"
        accepted: "must be accepted"
        empty: "can't be empty"
        blank: "can't be blank"
        too_long: "is too long (maximum is %{count} characters)"
        too_short: "is too short (minimum is %{count} characters)"
        wrong_length: "is the wrong length (should be %{count} characters)"
        not_a_number: "is not a number"
        not_an_integer: "must be an integer"
        greater_than: "must be greater than %{count}"
        greater_than_or_equal_to: "must be greater than or equal to %{count}"
        equal_to: "must be equal to %{count}"
        less_than: "must be less than %{count}"
        less_than_or_equal_to: "must be less than or equal to %{count}"
        other_than: "must be other than %{count}"
        odd: "must be odd"
        even: "must be even"
      template:
        header:
          one:    "1 error prohibited this %{model} from being saved"
          other:  "%{count} errors prohibited this %{model} from being saved

如果您对更改i18n版本不感兴趣,可以执行以下操作 在
config/locales/en.ym

如果
en:
已可用,请从ActiveRecord复制并粘贴

之后,停止服务器并再次启动,以正确显示错误消息

en:
  activerecord: 
    errors: 
      full_messages: 
        format: "%{attribute} %{message}"
      messages:
        inclusion: "is not included in the list"
        exclusion: "is reserved"
        invalid: "is invalid"
        confirmation: "doesn't match %{attribute}"
        accepted: "must be accepted"
        empty: "can't be empty"
        blank: "can't be blank"
        too_long: "is too long (maximum is %{count} characters)"
        too_short: "is too short (minimum is %{count} characters)"
        wrong_length: "is the wrong length (should be %{count} characters)"
        not_a_number: "is not a number"
        not_an_integer: "must be an integer"
        greater_than: "must be greater than %{count}"
        greater_than_or_equal_to: "must be greater than or equal to %{count}"
        equal_to: "must be equal to %{count}"
        less_than: "must be less than %{count}"
        less_than_or_equal_to: "must be less than or equal to %{count}"
        other_than: "must be other than %{count}"
        odd: "must be odd"
        even: "must be even"
      template:
        header:
          one:    "1 error prohibited this %{model} from being saved"
          other:  "%{count} errors prohibited this %{model} from being saved

谢谢你,现在可以了,但是。。。我没有安装gem i18 0.4.2,问题是,一旦我卸载了版本0.5.0,验证消息开始以正确的方式运行,但是现在,我没有gem i18n,因为版本0.4.2只进行了假安装,对于假安装,我的意思是:peppe@ubuntu:~$sudo gem install i18n-v 0.4.2已成功安装i18n-0.4.2 1 gem已安装安装i18n-0.4.2的ri文档。。。正在安装i18n-0.4.2的RDoc文档。。。peppe@ubuntu:~$gem list | grep i18npeppe@ubuntu:~$谢谢你,现在可以了,但是。。。我没有安装gem i18 0.4.2,问题是,一旦我卸载了版本0.5.0,验证消息开始以正确的方式运行,但是现在,我没有gem i18n,因为版本0.4.2只进行了假安装,对于假安装,我的意思是:peppe@ubuntu:~$sudo gem install i18n-v 0.4.2已成功安装i18n-0.4.2 1 gem已安装安装i18n-0.4.2的ri文档。。。正在安装i18n-0.4.2的RDoc文档。。。peppe@ubuntu:~$gem list | grep i18npeppe@ubuntu:~太棒了。我只是想解决这个问题。我发现这是一个i18n问题,我记得在另一个项目中遇到过这个问题。但不知道如何处理与您发布的.yml文件中的模板:header:other匹配的消息。非常有用。谢谢这是一个比改变gem版本更好的解决方案,它可能会产生意想不到的副作用,即使它解决了这个问题。我只是想解决这个问题。我发现这是一个i18n问题,我记得在另一个项目中遇到过这个问题。但不知道如何处理与您发布的.yml文件中的模板:header:other匹配的消息。非常有用。谢谢这是一个比改变gem版本更好的解决方案,即使它解决了这个问题,也可能会产生意想不到的副作用。