【发布时间】:2014-07-16 16:08:07
【问题描述】:
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)"
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 rails-i18n