js.erb 呈现为文本的模板
js.erb template rendered as text
我试图让我的销毁操作与 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 %>");
这里是我删除的地方 link(我也添加了 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>
试试这个
destroy.js.erb 文件:
$('#panel_<%= @image.id %>').remove();
我试图让我的销毁操作与 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 %>");
这里是我删除的地方 link(我也添加了 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>
试试这个
destroy.js.erb 文件:
$('#panel_<%= @image.id %>').remove();