【发布时间】:2026-01-21 02:40:01
【问题描述】:
大家好,我的模型中有以下代码
需要'RMagick'
类上传
has_attached_file :photo,
:styles => {
:thumb => ["100x100", :jpg],
:pagesize => ["500x400", :jpg],
},
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => ":attachment/:id/:style.:extension",
:bucket => 'your_deck',
:default_style => :pagesize
attr_accessor :x1, :y1, :width, :height
def update_attributes(att)
scaled_img = Magick::ImageList.new(self.photo.path)
orig_img = Magick::ImageList.new(self.photo.path(:original))
scale = orig_img.columns.to_f / scaled_img.columns
args = [ att[:x1], att[:y1], att[:width], att[:height] ]
args = args.collect { |a| a.to_i * scale }
orig_img.crop!(*args)
orig_img.write(self.photo.path(:original))
self.photo.reprocess!
self.save
super(att)
end
结束
此代码可以离线工作,但是在使用 Amazon S3 的 Heroku 上它无法工作,我尝试使用 to_file 的代码,它也无法工作
我收到以下错误
无法将数组转换为字符串
【问题讨论】:
标签: ruby-on-rails heroku paperclip