Paperclip.interpolates :normalized_file_name do |attachment, style|
attachment.instance.normalized_file_name
end
has_attached_file :avatar,
:path => ':rails_root/public/system/posts/:normalized_file_name-:style.:extension',
:default_url => '/images/missing_:style.png',
:url => '/system/posts/:normalized_file_name-:style.:extension',
:styles => {
:micro => ['600x300'],
:preview => ['200x']
}
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
# normalized file name for paperclip (avatar)
def normalized_file_name
extension = File.extname(avatar_file_name).downcase
"#{self.id}-#{self.title.parameterize}"
end
extend FriendlyId
friendly_id :title, use: :slugged
def normalize_friendly_id(input)
input.to_s.to_slug.normalize(transliterations: :russian).to_s
end
这是我的模型的一部分,当我请求某些图像时它工作正常(例如image_tag post.avatar.url(:micro))并根据此处描述的模型返回文件名。
BUT!如果我去/ public / system / posts /我可以看到原始文件名而不是我的插值(我在添加时从我的计算机中选择的那些文件)。这不是什么大不了的事,但我不喜欢在我的服务器或S3存储桶中使用非英文字符,我担心有一天它可能会导致获取这些图片(恕我直言)的问题。
有人可以通过paperclip(rails gem)判断这个插值对我的图像究竟是做什么的吗?谢谢!