开发者

Rails 3, Paperclip - Custom Interpolations

开发者 https://www.devze.com 2023-02-23 04:02 出处:网络
I\'ve been having some troubles making custom Interpolati开发者_JAVA技巧on, gone through every example I could find on web, but no matter what I did, had no success.

I've been having some troubles making custom Interpolati开发者_JAVA技巧on, gone through every example I could find on web, but no matter what I did, had no success. At the moment I have this:

Model

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 is field populated in form on upload with the image. The error I get on upload is:

Invalid argument - (C:/Users/.../stream20110410-384-stl2lk20110230-213-1fm2bab, C:/.../photo_upload/public/images/:img_name-original.jpg)


Seems to work if it's directly in the model:

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
0

精彩评论

暂无评论...
验证码 换一张
取 消