ruby-on-rails-3 – rails3 i18n accepted_nested_attributes_for how-to translate?

ruby-on-rails-3 – rails3 i18n accepted_nested_attributes_for how-to translate?,第1张

概述我正在使用Rails 3.2.6,这是一个示例案例: class Man < ActiveRecord::Base has_many :eyes accepts_nested_attributes_for :eyesendclass Eye < ActiveRecord::Base belongs_to :man validates_inclusion_of :color, i 我正在使用Rails 3.2.6,这是一个示例案例:

class Man < ActiveRecord::Base  has_many :eyes  accepts_nested_attributes_for :eyesendclass Eye < ActiveRecord::Base  belongs_to :man  valIDates_inclusion_of :color,in: { %w[brown green blue] }end

意见(在HAML中):

= form_for @man do |f|  - if @man.errors.any?    #error_explanation      %h2= t 'errors.messages.record_invalID',count: @man.errors.count      %ul        - @man.errors.full_messages.each do |msg|          %li= msg  = f.fIElds_for(:eyes) do |b|    .fIEld      = b.label :color      = b.text_fIEld :color  .actions    = f.submit :submit

it.yml:

it:  activerecord:    attributes:      customer:        eyes: Occhi      customer/eyes:        color: colore  errors:    models:      man/eyes:        attributes:          color:            inclusion: non valIDo

但是,颜色的标签没有翻译(但它是’actviterecord.attributes.eye.color’),错误消息中的属性只是“Occhi”,其余的是errors.model.eyes.attributes.color.inclusion而不是errors.models.man/eyes.attributes.color.inclusion

错误消息是errors.model.man.attributes.eyes.inclusion,但我如何区分它?它应该像“Occhi colore non valIDo”而不是“Occhi non valIDo”

解决方法 试试这个:

it:  activerecord:    attributes:      # set the name used in nested attribute error messages      customer/eyes:        color: Occhi colore  errors:    models:      # change the error message for eye color not included in the List      eye:        attributes:          color:            inclusion: non valIDo    messages:      # change the inclusion message globally      inclusion: non valIDo  helpers:    label:      # set the label used by form builder for labels      man[eyes_attributes]:        color: Occhi colore
总结

以上是内存溢出为你收集整理的ruby-on-rails-3 – rails3 i18n accepted_nested_attributes_for how-to translate?全部内容,希望文章能够帮你解决ruby-on-rails-3 – rails3 i18n accepted_nested_attributes_for how-to translate?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1290123.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存