【问题标题】:Rails full_messages missing labelRails full_messages缺少标签
【发布时间】:2014-10-10 10:29:35
【问题描述】:

由于某种原因,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'

【问题讨论】:

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


    【解决方案1】:

    对我来说,这是一个问题,因为我的 en.yml 中有以下内容(原因早已被遗忘)。

      errors:
        format: "%{message}"
    

    删除后标签正确显示。

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

      • 其实 spree core 已经有了这些翻译,所以我删除了我的条目。但由于它们已经存在于 spree_core/config/en.yml 中,它可能不是。感谢您的帮助。
      猜你喜欢
      • 2016-07-07
      • 2015-10-12
      • 2020-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-18
      • 2014-06-21
      相关资源
      最近更新 更多