ruby-on-railsrubyspreedeface

how can i use deface to change html that has tags with erb


I am new to spree and trying to make changes to the address form during checkout by removing some fields using deface. Which selector will I use now that the id value is in erb format. Here is the code sample from the form partial

    <% address_id = address_type.chars.first %>

    <p class="form-group" id=<%="#{address_id}zipcode" %>>
    <%= form.label :zipcode, Spree.t(:zip) %><% if address.require_zipcode? %><span class="required">*</span><br /><% end %>
    <%= form.text_field :zipcode, :class => "form-control #{'required' if address.require_zipcode?}" %>
  </p>
  <p class="form-group" id=<%="#{address_id}phone" %>>
    <%= form.label :phone, Spree.t(:phone) %><% if address.require_phone? %><span class="required">*</span><br /><% end %>
    <%= form.phone_field :phone, :class => "form-control #{'required' if address.require_phone?}" %>
  </p>
  <% if Spree::Config[:alternative_shipping_phone] %>
    <p class="form-group" id=<%="#{address_id}altphone" %>>
      <%= form.label :alternative_phone, Spree.t(:alternative_phone) %><br />
      <%= form.phone_field :alternative_phone, :class => 'form-control' %>
    </p>

Tried this as an example

Deface::Override.new(
    :virtual_path   => "spree/address/_form",
    :name           => "remove_phone",
    :remove         => "data-erb-id=&lt;%= \"address_type.chars.firstphone\" %&gt;",
)

but after running rake deface:get_result[spree/address/_form] I get the error: Nokogiri::CSS::SyntaxError: unexpected '=' after '[#]'

This is my first time working with spree but the documentation from the spree website doesn't seem to cover html tags with erb


Solution

  • Try This in your deface

    Deface::Override.new(:virtual_path  => "spree/address/_form",
                         :remove => "p[data-erb-id='<%=\"\#{address_id}phone\" %>']",
                         :name          => "remove_phone")