Ruby on rails Rails i18n属性无法通过JSON API工作
我们有一个RoR 4.2.5.1 API服务器和一个AngularJS前端 我正在努力让国际主义发挥作用,并且已经设置了我的en.ymlRuby on rails Rails i18n属性无法通过JSON API工作,ruby-on-rails,internationalization,rails-i18n,Ruby On Rails,Internationalization,Rails I18n,我们有一个RoR 4.2.5.1 API服务器和一个AngularJS前端 我正在努力让国际主义发挥作用,并且已经设置了我的en.yml en: activerecord: attributes: nas: calledstationid: 'AP Mac' errors: models: nas: attributes: calledstationid:
en:
activerecord:
attributes:
nas:
calledstationid: 'AP Mac'
errors:
models:
nas:
attributes:
calledstationid:
blank:
invalid:
taken: "has already been added to a location"
当我创建带有calledstationid的“nas”时,我希望“AP Mac已添加到某个位置”
相反,我得到的是“calledstationid…”
当我使用bang时,我可以看到被调用的StationID在日志中被ap mac替换
所以。。。我的问题是,为什么@nas.errors对象中的字段名没有更新?我怎样才能让它适用于多个地区
--编辑--
错误对象:
@messages={:calledstationid=>["has already been added to a location"]}>
您有两个选项来解决此问题 第一名: 编辑yaml文件并用以下内容替换该消息:
"%{attribute} has already been added to a location"
秒:
您得到的是符合当前YAML配置的标准和正确输出。但是要获得您想要的内容,在不更改YAML的情况下,需要使用
ActiveModel::Errors#full_messages
。因为此方法将属性名称预先添加到错误消息中以获取@nas中的值。Errors
您需要使用.save
或.valid?
<代码>。保存代码>将不会填充它。是的,我知道这一点。我在用!为了证明该值是正确的。那么问题是什么?阅读问题:我的问题是,为什么@nas.errors对象中的字段名没有更新?我怎样才能让它适用于多个地区。“太好了,这样就可以排序了。如果你给出答案,我会接受。干杯!在我的具体案例中,我更改了nas.errors-->nas.errors.full_消息
"%{attribute} has already been added to a location"