1

I am trying to add fields to spree admin using deface. I followed their tutorial, but they were inserting html using string. I tried to move that string into a html.erb file and reference the source as a partial, and got the following error.

undefined method `empty?' for nil:NilClass

Note: all done in spree extension

Code from tutorial that works:

# /overrides/add_sale_price_to_product_edit.rb
Deface::Override.new(:virtual_path => 'spree/admin/products/_form',
  :name => 'add_sale_price_to_product_edit',
  :insert_after => '[data-hook="admin_product_form_price"]',
  :text => "<%= f.field_container :sale_price do %>
    <%= f.label :sale_price, raw(Spree.t(:sale_price) + content_tag(:span, ' *')) %>
    <%= f.text_field :sale_price, :value =>
    number_to_currency(@product.sale_price, :unit => '') %>
    <%= f.error_message_on :sale_price %>
  <% end %>")

Using Partial (Doesn't work):

# /overrides/add_sale_price_to_product_edit.rb
Deface::Override.new(:virtual_path => 'spree/admin/products/_form',
  :name => 'add_sale_price_to_product_edit',
  :insert_after => '[data-hook="admin_product_form_price"]',
  :partial => 'simple_sale')


# /overrides/_simple_sale.html.erb
<div>
  <%= f.field_container :sale_price do %>
    <%= f.label :sale_price, raw(Spree.t(:sale_price) + content_tag(:span, ' *')) %>
    <%= f.text_field :sale_price, :value =>
    number_to_currency(@product.sale_price, :unit => '') %>
    <%= f.error_message_on :sale_price %>
  <% end %>
</div>
Community
  • 1
  • 1
harinsa
  • 3,176
  • 5
  • 33
  • 53

1 Answers1

0

My guess is that you need to have the partial in the views folder rather than the overrides folder -- /overrides is for .rb files -- partials and other view files need to go in the /views folder: /views/shared or something.

davidwmartin
  • 63
  • 2
  • 9