Paperclip.interpolates :day do |attachment, style|
attachment.instance.created_at.strftime("%Y%m%d")
end
Paperclip.interpolates :hour do |attachment, style|
attachment.instance.created_at.strftime("%Y%m%d%H")[attachment.instance.created_at.strftime("%Y%m%d%H").length-2,2]
end
has_attached_file :avatar,
:url => "/pictures/:attachment/:hour/:id/:basename.:extension", # 文件访问路径
:path => ":rails_root/public/pictures/:attachment/:hour/:id/:basename.:extension", # 文件存放路径 :rails_root 给用户设置存放的root权限
:styles => { :medium => "300x300>", :thumb => "100x100>" }
validates_attachment_size :avatar, :less_than => 2.megabytes
validates_attachment_content_type :avatar, content_type: ["text/csv"] # 安装imagemagick
如上上传的时候可以在 public 下生成 pictures/avatars/20160328/8/a.jpg 类似的文件夹,怎么可以在 20160328 下生成以当天小时为单位的文件件? 生成二级文件夹的问题已解决,代码已贴出,怎么上传 csv 和 pdf 等文件呢?