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>