Last active
August 29, 2015 14:10
-
-
Save jacoyutorius/c9fbb9bfe47ed84ea781 to your computer and use it in GitHub Desktop.
Paperclipでアップロードするファイルのcontent_typeの確認方法 ref: http://qiita.com/jacoyutorius/items/ce7902f8502d35818cf8
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
| file -I sample-excel.xls | |
| sample-excel.xls: application/vnd.ms-excel; charset=binary |
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
| file -I sample-powerpoint.pptx | |
| sample-powerpoint.pptx: application/zip; charset=binary |
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
| validates_attachment_content_type col, | |
| :content_type => ["application/vnd.ms-excel", "application/zip"] |
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
| def validate_each(record, attribute, value) | |
| ~(省略)~ | |
| if record.errors.include? attribute | |
| binding.pry #ブレークポイント | |
| record.errors[attribute].each do |error| | |
| record.errors.add base_attribute, error | |
| end | |
| 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
| record.{アップロードするフィールド}_contant_type |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment