我正在使用 Rails4 和 mongoid-paperclip
mongoid-paperclip (0.0.9)
paperclip (>= 2.3.6)
我想更改文件名,所以我的课程如下,
class Icon
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Paperclip
has_mongoid_attached_file :icon,
:path => ":rails_root/public/system/:attachment/:id/:style/:filename",
:url => "/system/:attachment/:id/:style/:filename",
:styles => {
:small => { :geometry => "100x100"
}
}
before_post_process :rename_avatar
private
def rename_avatar
extension = File.extname(icon_file_name).downcase
self.icon.instance_write(:file_name, "#{extension}")
end
end
如何实现这个!!!