我正在尝试使用Deface在partial for Spree中将max值添加到此表单。
Deface::Override.new(
:virtual_path => 'spree/products/_cart_form',
:name => 'modify_max_add_to_cart',
:replace_contents => ".add-to-cart",
:text => "
<%= number_field_tag (@product.variants_and_option_values.any? ? :quantity : 'variants[#{@product.master.id}]\'),
1, :class => 'title', :min => 1, :max => @product.limit_qty %>
<%= button_tag :class => 'large primary', :id => 'add-to-cart-button', :type => :submit do %>
<%= Spree.t(:add_to_cart) %>
<% end %>
")问题是,它似乎出了问题,因为那里有实例变量。
undefined method master for nil:NilClass
我该如何正确地做到这一点?
发布于 2013-09-04 04:58:53
当您更改此行时
<%= number_field_tag (@product.variants_and_option_values.any? ? :quantity : "variants[#{@product.master.id}]")为了使用单引号,您打破了下面这段代码中出现的变量插值:
"variants[#{@product.master.id}]"您可以通过将行更改为:
<%= number_field_tag (@product.variants_and_option_values.any? ? :quantity : \"variants[#{@product.master.id}]\")实际上,与其使用文本替换,不如考虑使用部分替换。使用多行代码会更清晰一些。
https://stackoverflow.com/questions/18542862
复制相似问题