我的视图包含各种员工的详细信息,我必须为每个员工上传图像并最后保存。我想在保存之前查看每个图像的图像预览,但它需要 localhost 路径并且不显示图像预览。它显示错误:“NetworkError:404 Not Found -localhost:3000/rails.png”
在视图中
<% @person.each do |person| %>
<td><%= person.name %></td>
<td><%= person.date %></td>
<td><input id="<%= person.id %>" type='file' class="imageUploader" multiple="true" ></td>
<td class="image_container"> <img id="image_<%= person.id %>" src="#" alt="Image" width="100" height="100"></td>` here
</tr>
<% end %>
在 application.js::
$('.imageUploader').change(function() {
var target_image = $(this).val();
$(this).parent('td').parent("tr").children('td.image_container').html("<img src="+target_image+">");
console.log(target_image);
});