もう一度あなたの助けが必要です。次に、Carrierwaveがアップロードしたファイル(私の場合は画像)を使用して削除する方法を理解する必要があります。
models / attachment.rb:
class Attachment < ActiveRecord::Base
belongs_to :attachable, :polymorphic => true
attr_accessible :file, :file
mount_uploader :file, FileUploader
end
models / post.rb:
class Post < ActiveRecord::Base
attr_accessible :content, :title, :attachments_attributes, :_destroy
has_many :attachments, :as => :attachable
accepts_nested_attributes_for :attachments
end
* views / posts / _form.html.erb:*
<%= nested_form_for @post, :html=>{:multipart => true } do |f| %>
<% if @post.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>
<ul>
<% @post.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div id="field">
<%= f.label :Nosaukums %>:<br /><br />
<%= f.text_field :title %><br /><br />
</div>
<div id="field">
<%= f.label :Raksts %>:<br /><br />
<%= f.text_area :content %><br /><br />
</div>
<%= f.fields_for :attachments do |attachment| %>
<% if attachment.object.new_record? %>
<%= attachment.file_field :file %>
<% else %>
<%= image_tag(attachment.object.file.url) %>
<%= f.check_box :_destroy %>
<% end %>
<% end %>
<%= f.submit "Publicēt", :id => "button-link" %>
<% end %>
以前にアップロードしたファイルを削除しようとすると、次のエラーが発生します。
unknown attribute: _destroy
1つだけでなく複数のファイルをアップロードしているため、問題がある可能性があります。