我是 ruby?? on rails 的新手,我想更改我上傳的圖片的名稱,謝謝
resized_image = MiniMagick::Image.read(picture.image.download)
resized_image = resized_image.combine_options do |b|
b.resize '2760>'
b.quality '80'
end
v_filename = picture.image.filename
v_content_type = picture.image.content_type
picture.image.purge
picture.image.attach(io: File.open(resized_image.path), filename: v_filename, content_type: v_content_type)
end```
uj5u.com熱心網友回復:
正如評論中提到的@elmd00picture.image.filename是類,ActiveStorage::Filename因此gsub無法解決我們需要首先使用to_s方法將其轉換為字串的問題,然后我們可以使用下劃線gsub替換空格。( )(_)
v_filename = v_filename.to_s.gsub(" ", "_")
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/358378.html
上一篇:使用ieget方法而不是通過單擊按鈕來執行操作是否存在真正的問題
下一篇:CocoonGem呈現兩次形態
