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
I am trying to replace this view Spree form view
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>
.
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 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.