Rails full_messages缺少标签

时间:2014-10-10 10:29:36

标签: ruby-on-rails ruby-on-rails-3 spree

由于某些原因,rails full_messages缺少标签,只是包含错误而不知道它与哪个字段有关:

[3] pry(#<Spree::CheckoutController>)> @order.errors
=> #<ActiveModel::Errors:0x007fce1caa8218
 @base=
  #<Spree::Order id: 87, number: "R442456123", item_total: #<BigDecimal:7fce1c57a4a8,'0.6495E2',18(36)>, total: #<BigDecimal:7fce1c5cd0e0,'0.6495E2',18(27)>, state: "address", adjustment_total: #<BigDecimal:7fce1c5cd270,'0.0',9(27)>, user_id: 57, completed_at: nil, bill_address_id: nil, ship_address_id: nil, payment_total: #<BigDecimal:7fce1cb184a0,'0.0',9(27)>, shipping_method_id: nil, shipment_state: nil, payment_state: nil, email: "nick@1-night.co.nz", special_instructions: nil, created_at: "2014-10-10 09:47:21", updated_at: "2014-10-10 09:47:24", currency: "USD", last_ip_address: "127.0.0.1", created_by_id: 57, channel: "spree", tax_total: #<BigDecimal:7fce1cb217d0,'0.0',9(27)>>,
 @messages=
  {:"bill_address.phone"=>["can't be blank"],
   :"ship_address.phone"=>["can't be blank"]}>
[4] pry(#<Spree::CheckoutController>)> @order.errors.full_messages
=> ["can't be blank", "can't be blank"]

我在en.yml中添加了属性 - 如何获取包含模型名称的完整消息,即:["Billing address phone can't be blank", "Shipping address phone can't be blank"]

使用以下内容:

gem 'rails', '4.0.2'
gem 'spree', '2.1.4'

2 个答案:

答案 0 :(得分:1)

对我来说,这是一个在我的en.yml中有(长期以来被遗忘的理由)以下内容的问题。

  errors:
    format: "%{message}"

删除后,标签显示正确。

答案 1 :(得分:0)

我认为你在en.yml文件中添加属性的方式是错误的。你应该这样做:

en:
  activerecord:
    attributes:
      spree/order/bill_address:
        phone: Billing address phone
      spree/order/ship_address:
        phone: Shipping address phone