我正在使用 Rails 3.2.6,这是一个示例:
class Man < ActiveRecord::Base
has_many :eyes
accepts_nested_attributes_for :eyes
end
class 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”