【问题标题】:carrierwave rails 5 don't store the whole path of image filecarrierwave rails 5 不存储图像文件的整个路径
【发布时间】:2018-04-02 11:38:59
【问题描述】:

Carrierwave Rails 5 只存储图像文件名而不是整个路径名。

在models/profile.rb中

mount_uploader :avatar, AvatarUploader

它将图像文件存储在正确的上传文件夹中,因此我的 AvatarUploader 工作正常。 但是 :avatar 属性只有文件名而不是整个路径名。

profile.avatar =>

"thumb_8eb67953-d383-4c1f-a42d-662903386814.jpg"

我是否需要在 models/profile.rb 中使用 :avatar 属性执行 before_saveafter_save 以指向正确的位置?

../app/assets/images/uploads/profile/avatar/20/thumb_8eb67953-d383-4c1f-a42d-662903386814.jpg

感谢您的帮助,

【问题讨论】:

    标签: save ruby-on-rails-5 carrierwave pathname


    【解决方案1】:

    你可以使用 profile.avatar.url

    它将给出文件的完整路径。更多参考请阅读This.

    【讨论】:

    • 谢谢, = >"/app/assets/images/uploads/profile/avatar/20/e3ec13bc-f5c3-4703 -89d8-65f2f35ba42a.jpg" 现在我收到此错误 ActionController::RoutingError (No route matches [GET] "/app/assets/images/uploads/profile/avatar/20/thumb_e3
    • 如果能解决您的问题,请接受我的回答。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多