简体   繁体   中英

How to save image url in database through carrierwave

如何通过使用carrierwave将图像的url而不是图像名称保存在数据库中?

Assuming you have image as the field mounted in User model for carrierwave, just to get the url you could do

user = User.first
user.image.url

But if you definitely need an image url then you can add a new column image_url then you could add a after_save method in your model and update the field with the url.

# in user.rb
after_save do |user|
  user.update(image_url, user.image.url)
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM