1

번역 된 오류 메시지에 대한 지원을 구현하려는 양식 (simple_form 사용)이 있습니다. 모든 번역은 오류 메시지를 제외하고 나타납니다.사용자 정의 오류 메시지 번역

내 고객 모델은 다음과 같습니다

class Customer < ActiveRecord::Base 
    attr_accessible :name, :phone, :email, :contact_method 

    validates_presence_of :phone, :email, :contact_method, :message => I18n.t(:required) 
end 

fr.yml 파일을 다음과 같이

fr: 
    name: 'Nom' 
    phone: 'Téléphone' 
    email: 'Courriel' 
    contact_method: 'Méthode de contact' 
    required: 'Requis' 

나의 양식은 다음과 같습니다

= simple_form_for @customer do |f| 
    = f.input :name, label: t(:name) 
    = f.input :phone, label: t(:phone) 
    = f.input :email, label: t(:email) 

내가 부족 뭔가가 있나요?

답변

3

먼저 Symbolvalidates_presence_of을 사용해야합니다. 수동으로 국제화로 번역하지 마십시오 둘째

validates_presence_of :phone, :email, :contact_method, :message => :required 

을 다음과 같이 로케일 파일에 오류 메시지에 대한 번역을 추가 :

activerecord: 
    errors: 
    models: 
     customer: 
     required: 'Requis' 
+0

우수한. 고맙습니다! – dspencer

+0

도와 주셔서 감사합니다 :) –

관련 문제