Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save jacoyutorius/c9fbb9bfe47ed84ea781 to your computer and use it in GitHub Desktop.
Paperclipでアップロードするファイルのcontent_typeの確認方法 ref: http://qiita.com/jacoyutorius/items/ce7902f8502d35818cf8
file -I sample-excel.xls
sample-excel.xls: application/vnd.ms-excel; charset=binary
file -I sample-powerpoint.pptx
sample-powerpoint.pptx: application/zip; charset=binary
validates_attachment_content_type col,
:content_type => ["application/vnd.ms-excel", "application/zip"]
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
record.{アップロードするフィールド}_contant_type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment