我一直在尝试创建自定义插值器,浏览了网上能找到的所有示例,但无论我做了什么都没有成功。目前我有这个:
模型
has_attached_file :photo,
:path => ":rails_root/public/images/:img_name-:style.:extension",
:styles => {
:original => '100x100',
:thumb => '30x30'
}
initializers/paperclip.rb
Paperclip.interpolates :img_name do |attachment, style|
attachment.instance.img_name
end
img_name
是上传表单中图片字段的名称。上传时出现的错误为:
无效参数 - (C:/Users/.../stream20110410-384-stl2lk20110230-213-1fm2bab, C:/.../photo_upload/public/images/:img_name-original.jpg)