2013-02-15 44 views
0

爲什麼渲染渲染爲什麼:locals當它從js.erb文件調用不起作用?裏面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>: 

在計算器上的一些帖子說該代碼應該可以工作。任何幫助?

回答

1

在您使用當地人應該作爲第二個參數傳遞,這樣的語法:

render(partial: "/admin/products/variant_image_preview", :locals => {:image => @variant_image}) 

render("/admin/products/variant_image_preview", :image => @variant_image) 

你可以用更具聲明調用替換這句法