Again I need your help. Now I need to understand how I can remove Carrierwave with downloadable files (in my case, images).
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 %>
When I try to delete the previous downloaded file, I have this error:
unknown attribute: _destroy
Perhaps there is a problem because I have several file uploads, not just one.
source share