我在制作自定义插值时遇到了一些麻烦,我在网上找到了每一个例子,但无论我做了什么,都没有成功。现在我有这个:
模型has_attached_file :photo,
:path => ":rails_root/public/images/:img_name-:style.:extension",
:styles => {
:original => '100x100',
:thumb => '30x30'
}
初始化/paperclip.rb
Paperclip.interpolates :img_name do |attachment, style|
attachment.instance.img_name
end
img_name
是在上传时用图像填充在表单中的字段。我在上传时得到的错误是:
无效参数- (C:/Users/…)/stream20110410 - 384 - stl2lk20110230 - 213 - 1 fm2bab C:/…/photo_upload/公共/图片/:img_name-original.jpg)
如果直接在模型中,似乎可以工作:
class Model < ActiveRecord::Base
Paperclip.interpolates :img_name do |attachment, style|
attachment.instance.img_name
end
has_attached_file :photo,
:path => ":rails_root/public/images/:img_name-:style.:extension",
:styles => {
:original => '100x100',
:thumb => '30x30'
}
end