Last active
August 29, 2015 14:12
-
-
Save jacoyutorius/f16e52d263e863e88560 to your computer and use it in GitHub Desktop.
Paperclipのattachmentの削除方法 ref: http://qiita.com/jacoyutorius/items/3b597944363ba7fccf03
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # line 259 | |
| def destroy | |
| clear | |
| save | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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