Carrierwave Datei löschen

Wieder brauche ich Eure Hilfe. Jetzt muss ich verstehen, wie ich das löschen kann mit Carrierwave hochgeladenen Dateien (in meinem Fall Bilder).

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-Code.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 %>

Wenn ich versuche zu löschen, die bisherigen hochgeladenen Datei habe ich diese Fehlermeldung:

unknown attribute: _destroy

Vielleicht ist es ein problem, weil ich mehrere Datei-uploads nicht nur eine.

InformationsquelleAutor RydelHouse | 2013-02-13

Schreibe einen Kommentar