Ruby on Rails 4.1사용자 정의 메시지 및 속성 이름 검증에 대한 유효성 검사
양식의 유효성 검사가 모델에서 확인되었습니다. 메시지 앞에 특성 이름을 표시하는 사용자 지정 메시지가 있습니다.
en.yml 파일에서 속성 변환을 지정하려고하거나 속성 이름 만 제거하려고합니다. 오류가 발생하지는 않지만 사용자 지정 메시지를 사용하지 않고 특성 만 휴먼 화합니다.
예를 들어, 하나의 메시지는 * Cc name your name on the credit card cannot be blank
입니다. Your name on the credit card cannot be blank
또는 Credit card name cannot be blank
으로 말하고 싶습니다.
모델 :
class Payment < ActiveRecord::Base
validates_presence_of :telephone, :email, :address1, :city, :state, :postal_code, :country, :cc_type, :cc_number, :ccv, :expires_on, :ship_name, :ship_address1, :ship_city, :ship_state, :ship_postal_code, :ship_country
validates_presence_of :cc_name,
:message => ' Your name on the credit card cannot be blank'
validates_presence_of :name_auth,
:message => ' Your name authorizing the purchase cannot be blank'
오류 메시지 파일 :
<% if @payment.errors.any? %>
<div id="error_explanation">
<div class="alert alert-error">
The form contains <%= pluralize(@payment.errors.count, "error") %>
</div>
<ul>
<% @payment.errors.full_messages.each do |msg| %>
<li>* <%= msg.humanize %></li>
<% end %>
</ul>
</div>
<% end %>
en.yml 파일 :
en:
activerecord:
attributes:
cc_name: "Credit card name"
name_auth: "Authorizing name"
date_auth: "Authorized date"
card_holder_auth: "Authorized card holder"
charge_auth: "Authorizing payment"
cc_number: "Credit card number"
ccv: "Card code verification (CCV)"
방금 시도한 결과, # {attribute_name}을 (를) 공백 메시지에 배치했습니다. * Cc 이름의 신용 카드 이름은 코드와 함께 비워 둘 수 없습니다. : / – DDDD