为什么渲染从文件:locals
调用时为什么不起作用?js.erb
这是我的create.js.erb
:
$("#div").before("<%= escape_javascript(render("/admin/products/variant_image_preview", :locals => {:image => @variant_image})) %>");
variant_image_preview.html.erb
:
<div id="variant_image_<%= image.id %>">
<%= image_tag image.image_url(:thumb), width: 114, height: 88 %>
<% form_name = "product[variants_attributes][1][images_attributes][#{Time.now.to_f}]" %>
<input type="hidden" value="<%= image.id %>" name="<%= form_name %>[id]">
<a id="<%= image.id %>" class="remove_image" title="Remover imagem">
<img src="/assets/bg_close.png" alt="Remover imagem">
</a>
</div>
在variant_image_preview.html.erb 的第一行我得到这个错误:
NameError - undefined local variable or method `image' for #<#<Class:0x0000000f4f6e88>:0x000000101332c8>:
StackOverflow 上的一些帖子说这段代码应该可以工作。有什么帮助吗?