使用Deface预填充帐单地址

时间:2013-09-12 18:29:02

标签: ruby-on-rails spree deface

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

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 form view

如上所述,但破损日志说

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

正在运行的spree实例的id为order_bill_address_attributes_phone,并包含在<p>中。 任何的想法?谢谢你的帮助!

1 个答案:

答案 0 :(得分:6)

放手一搏:

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。