다시 귀하의 도움이 필요합니다. 이제 Carrierwave에서 업로드 한 파일 (내 경우에는 이미지)을 삭제하는 방법을 이해해야합니다.반송파 파일 삭제
모델/attachment.rb :
class Attachment < ActiveRecord::Base
belongs_to :attachable, :polymorphic => true
attr_accessible :file, :file
mount_uploader :file, FileUploader
end
모델/post.rb :
class Post < ActiveRecord::Base
attr_accessible :content, :title, :attachments_attributes, :_destroy
has_many :attachments, :as => :attachable
accepts_nested_attributes_for :attachments
end
* 보기/게시물/_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
아마 문제가 있습니다.
네, 본 적이 있지만'remove_file'을 시도 할 때 :이 오류가 있습니다 :'정의되지 않은 메소드 'remove_file'for #' –
RydelHouse
메소드를 호출하려고합니다. 'remove_file'? 문서에 따르면,이 메소드는'remove_file!'이라고 불립니다 (느낌표에주의하십시오). – Tomdarkness
나는이 모든 일들도했지만, 오류가있다. 팁을위한 – RydelHouse