我已经正确设置了cocoon gem并且一切正常,我可以根据需要上传图片但是当我点击删除时,它似乎不会删除图像。这是我的代码:
_image_fields.html.erb
x-foo.outer x-foo {
--xbg: red !important;
/* Works */
}
这是我的表格:
<div class="nested-fields">
<%= f.text_area :description %>
<%= f.file_field :picture %>
<%= link_to_remove_association "remove", f %>
</div>
控制器中的:
<div class="imagefield">
<h2>Images</h2>
<h4>upload images</h4>
<hr>
<div class="customgap">
<div class="images">
<%= f.fields_for :images do |image| %>
<%= render 'image_fields', f: image %>
<% end %>
<div class="links">
<%= link_to_add_association 'add image', f, :images %>
</div>
</div>
</div>
</div>
图片模型
images_attributes: [:id, :description, :picture, :_destroy]
答案 0 :(得分:1)
我必须在控制器中:allow_destroy => true
accepts_nested_attributes_for :images, :allow_destroy => true