2011-01-25 3 views
3

이것은 잠시 동안 나를 괴롭 히고 있습니다. 이 문제는 모든 모델에서 발생하지만 예제 중 하나 인 Quiz를 사용합니다.errors.full_messages : 속성 이름이 두 번 나타납니다.

퀴즈는 다음과 같은 검증 있습니다

validates_presence_of :size, :style 

내가 국제화를 사용하고, 그리고 난 내 번역 파일에 설정 다음했다 : (이 그냥 표준 오류 메시지입니다,하지만 난 그들을 포함 시켰습니다 내가) 어떤 특정 모델에 대한

activerecord: 
    errors: 
    messages: 
     inclusion: "{{attribute}} is not included in the list" 
     invalid: "{{attribute}} is invalid" 
     empty: "{{attribute}} can't be empty" 
     blank: "{{attribute}} can't be blank" 
     record_invalid: "Validation failed: {{errors}}" 

문제를 무시하려는 경우 내 en.yml가 있도록이이며, 구조를 쉽게 알 : 내가 유효성 검사에 실패한하는 새로운 퀴즈를 만들 경우, 다음 봐 quiz.errors.full_messages에서 각 오류 메시지의 특성은 전체 메시지 E :

>> quiz = Quiz.create 
=> <unsaved quiz object> 
>> quiz.errors.full_messages 
=> ["Size Size can't be blank", "Style Style can't be blank"] 

나는 메시지는, 예를 들면, 이유를 이해하지 않는, "Size can't be blank"

모든 아이디어를 누구 "Size Size can't be blank"하지?

+0

{{속성}}'에서 유효성 검사 메시지의 각 : 확실히 모든 올바르게 레일 버전에서 en.yml을 사용하여 얻을하려면 은은에 있습니다? 일반적으로 "목록에 포함되지 않았습니다."와 같은 오류 메시지 만 포함됩니다. 속성은 로케일 파일의'activerecord.errors.full_messages.format'에 기초하여 자동으로 추가됩니다. 기본값은'% {attribute} % {message} "' – sikachu

+0

Hi Sikachu입니다. 그것이 벤더 레일에 있었던 방법입니다. 나는 단지 en.yml 파일 (주석 처리 된 파일)에 해당 파일의 내용을 복사 한 다음 필요에 따라 주석을 제거하고 수정합니다. –

답변

8

이 또한 있어야한다. 당신이`추가 할 필요가 왜 특별한 이유가 lib/ruby/gems/1.8/gems/activemodel-3.0.3/lib/active_model/locale/en.yml

+0

감사합니다 Gertas, 그게 내가 알아 낸거야, 내가 기반으로 광산을 공급 업체 레일보다는 오히려 activemodel 3 (나는 레일 2.3.4를 사용하고 있습니다) –

4

난 그냥이를 생각하고 내가이 문제를 한 경우 다른 사람에 나 자신에 대답 거라고 생각 :

activerecord: 
    errors: 
    full_messages: 
     format: "{{message}}"  
    #define standard error messages, which we can overide on per model/per attribute basis further down 
    messages: 
     inclusion: "{{attribute}} is not included in the list" 
     exclusion: "{{attribute}} is reserved" 

문제는 것이 었습니다 : 난 내 번역의 액티브 부분 따라서 파일을 수정했다 activerecord.errors.full_messages.format 키가 (vendor/rails/activerecord/lib/active_record/locale/en.yml에서) "{{attribute}} {{message}}"로 설정되고 메시지가 "{{attribute}}은 비워 둘 수 없습니다"로 설정되었습니다. 그래서 full_message는 "{{attribute}} {{attribute}}이 (가) 공백 일 수 없으므로"나오고있었습니다. 그것을 "{{message}}"로 변경하면이 문제가 해결되었습니다.

en: 
    errors: 
    # The default format to use in full error messages. 
    format: "%{attribute} %{message}" 

을 그리고 다른 번역은 더 이상 %{attribute}을 포함하지 않아야 :