我正在尝试使用ajax使我的销毁操作工作,所以我在删除图像时不必刷新页面..问题是当我尝试使用ajax时它会删除图像,但它会显示此文本:
<%= j render @category.images
......这是我的毁灭行动:
def destroy
@image = @category.images.find(params[:id])
@image.destroy
respond_to do |format|
format.html { redirect_to category_path(@category) }
format.js
end
end
destroy.js.erb文件:
$('#panel_<%= @image.id %>').html("<%= j render @category.images %>");
这里是我的删除链接(我添加了remote:true):
<% @category.images.each do |image| %>
<div class="col-md-6">
<div class="panel panel-default panel-show" id= "panel_<%= image.id %>">
<div class="panel-body panel-body-show">
<%= image_tag(image.photo.url(:thumb), class: "img-in img-responsive") %>
<%= link_to "delete", category_image_path(@category, image), remote: true, method: :delete, data: {confirm: "Are you sure?"} %> <%= link_to "edit", edit_category_image_path(@category, image) %>
<ul class="imgs-tables">
<li><h2><%= image.i_name %></h2></li>
<hr class="for-title">
<li class="second-one"><p><%= image.i_bio %></p></li>
<% if image.price %>
<li class="price-title"><h3> Price: </h3> </li> <li class="price-li"><h4 class="for-price"><%= image.price %><i class="fa fa-ils"></i></h4></li><br/>
<hr class="price-line-up">
<hr class="price-line-down">
<% end %>
</ul>
<ul class="sub-images-show">
<% image.sub_images.each do |sub_image| %>
<li><%= image_tag(sub_image.small_image.url(:small)) %></li>
<% end %>
</ul>
</div>
</div>
</div>
<% end %>
和她是一个图像,显示文本呈现的位置
<blockquote class="imgur-embed-pub" lang="en" data-id="a/G9FVD"><a href="//imgur.com/G9FVD"></a></blockquote><script async src="//s.imgur.com/min/embed.js" charset="utf-8"></script>
答案 0 :(得分:0)
试试这个
destroy.js.erb文件:
$('#panel_<%= @image.id %>').remove();