[英]Using Deface to prepopulate Billing Address
I am trying to populate my billing address with prepopulated values. 我正在尝试使用预填充值填充我的帐单地址。 I have written a deface as :
我写的污损为:
Deface::Override.new(:virtual_path => 'spree/address/_form',
:name => 'prepopulate_billing_address',
:set_attributes => 'p#order_bill_address_attributes_phone',
:attributes => {:value => "122344"}
)
and the content belongs to app/overrides/autofill_billing_address.rb
并且内容属于
app/overrides/autofill_billing_address.rb
I am trying to replace this view Spree form view 我正在尝试替换此视图Spree表单视图
with the above deface but the deface logs say 以上污损,但污损日志说
Deface: 'prepopulate_billing_address' matched 0 times with 'p#order_bill_address_attributes_phone'
The id from the spree instance running is order_bill_address_attributes_phone
and is wrapped in <p>
. 运行的spree实例的ID为
order_bill_address_attributes_phone
,并包装在<p>
。 Any idea? 任何想法? Thanks for the help!
谢谢您的帮助!
Give this a go: 试试看:
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' %>"
One helpful thing is to use the rake tasks for testing what matches what: 一件有用的事情是使用rake任务来测试什么匹配什么:
rake deface:test_selector['spree/address/_form','code[erb-loud]:contains("phone_field :phone")']
You can see that your selectors from before wouldn't work because this: 您可以看到以前的选择器不起作用,因为:
rake deface:test_selector['spree/address/_form','p']
returns: 返回:
# 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
At this point the ID hasn't been set yet because as zrl3dx mentioned, you're operating on the erb before it's been evaluated. 到目前为止,尚未设置ID,因为正如zrl3dx所述,您需要在评估erb之前对其进行操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.