0

我正在尝试使用预填充的值填充我的帐单地址。我写了一个污点:

Deface::Override.new(:virtual_path => 'spree/address/_form',
                                  :name => 'prepopulate_billing_address',
                                  :set_attributes => 'p#order_bill_address_attributes_phone',
                                  :attributes => {:value => "122344"}
                                  )

并且内容属于app/overrides/autofill_billing_address.rb

我正在尝试替换此视图 Spree 表单视图

有上述污损,但污损日志说

Deface: 'prepopulate_billing_address' matched 0 times with 'p#order_bill_address_attributes_phone'

正在运行的 spree 实例的 idorder_bill_address_attributes_phone被包裹在<p>. 任何的想法?谢谢您的帮助!

4

1 回答 1

7

试一试:

Deface::Override.new :virtual_path => 'spree/address/_form',
                     :name => 'prepopulate_billing_address',
                     :replace => 'code[erb-loud]:contains("phone_field :phone")',
                     :text => "<%= form.phone_field :phone, :class => 'required', :value => '122344' %>"

一件有用的事情是使用 rake 任务来测试匹配的内容:

rake deface:test_selector['spree/address/_form','code[erb-loud]:contains("phone_field :phone")']

您可以看到之前的选择器不起作用,因为:

rake deface:test_selector['spree/address/_form','p']

返回:

# snip
---------------- Match 10 ----------------
<p class="field" id='<%="#{address_id}phone" %>'>
    <%= form.label :phone, Spree.t(:phone) %><span class="required">*</span><br><%= form.phone_field :phone, :class => 'required', :value => '122334' %>
  </p>
# snip

此时尚未设置 ID,因为正如 zrl3dx 所提到的,您在评估之前对 erb 进行操作。

于 2013-09-12T21:33:25.030 回答