4

나는 레일 3.2.6를 사용하고 있는데이 예제의 경우이다 : (HAML에서)rails3 i18n accepts_nested_attributes_for 번역 방법은 무엇입니까?

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 

조회수 :

= 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.models.man/eyes.attributes.color.inclusion

오류 메시지는 errors.model.man.attributes.eyes.inclusion이지만 어떻게 구분할 수 있습니까? 그것은 "오치 COLORE 비 valido"대신 "오치 비 valido"뭔가를해야

답변

6

이 밖으로 시도 : 이것에 대한

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 
+0

감사합니다! 방금 ActiveRecord가 그 열쇠를 찾고있는 곳을 찾으려고 한 시간을 잃었습니다. –

+2

@JoelCogen 특정 키를 식별하는 가장 좋아하는 것은 요청 된 키를 기록하는 I18n :: Backend :: Simple # 조회의 원숭이 패치입니다. – graywh