Paperclip 如何更改basename(文件名)? [英] Paperclip how to change basename (filename)?

查看:54
本文介绍了Paperclip 如何更改basename(文件名)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更改照片的基本名称(文件名):

I am trying to change the basename (filename) of photos:

在我的模型中,我有:

  attr_accessor :image_url, :basename

  has_attached_file :image,
          :styles => { :original => ["300x250>", :png], :small => ["165x138>", :png] },
          :url  => "/images/lille/:style/:id/:basename.:extension",
          :path => ":rails_root/public/images/lille/:style/:id/:basename.:extension"
before_save :basename
private

  def basename
  self.basename = "HALLLO"
  end

但是文件名根本没有改变.

But the filename is not changed at all.

推荐答案

如果您是直接分配文件,您可以这样做:

If you are assigning the file directly you can do this:

photo.image = the_file
photo.image.instance_write(:file_name, "the_desired_filename.png")
photo.save

这篇关于Paperclip 如何更改basename(文件名)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆