Skip to content

Instantly share code, notes, and snippets.

@jacoyutorius
Last active August 29, 2015 14:12
Show Gist options
  • Select an option

  • Save jacoyutorius/f16e52d263e863e88560 to your computer and use it in GitHub Desktop.

Select an option

Save jacoyutorius/f16e52d263e863e88560 to your computer and use it in GitHub Desktop.
Paperclipのattachmentの削除方法 ref: http://qiita.com/jacoyutorius/items/3b597944363ba7fccf03
# line 259
def destroy
clear
save
end
class Picture < ActiveRecord::Base
[:picture].each do |col|
has_attached_file col,
styles: {:medium => "300x300", :thumb => "100x100"},
default_url: "common/:style/icon-file-nodata.png",
url: "/data/images/:class/:parent_id/:id/:attachment/:style/:filename"
validates_attachment_content_type col,
:content_type => ["image/png", "image/jpg", "image/jpeg"]
end
end
Picture.first
Picture.first.picture
#=> Paperclip::Attachment
Picture.first.picture.destroy
#=>
[paperclip] deleting ~/pictures/1/pictures/original/5558.jpg
[paperclip] deleting ~/pictures/1/pictures/medium/5558.jpg
[paperclip] deleting ~/pictures/1/pictures/thumb/5558.jpg
[paperclip] deleting ~/pictures/1/pictures/large/5558.jpg
=> true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment