【问题标题】:Get Full URL for ActiveStorage image获取 ActiveStorage 图像的完整 URL
【发布时间】:2018-08-28 12:38:09
【问题描述】:

以下将返回一个可以工作的 URL,但是有没有更好的方法不需要字符串连接?我不想公开 service_url,因为该 URL 已过期。

 root_url + url_for(object.image.variant(resize: '140x140')) 

最终,我想做这样的事情

object.image.variant(resize: '140x140').absolute_url

【问题讨论】:

    标签: ruby-on-rails rails-activestorage


    【解决方案1】:

    我不确定这是否是推荐的方式,但您可以使用 polymorphic_url 帮助器:

    polymorphic_url object.image.variant(resize: '140x140')
    

    【讨论】:

    • 非常感谢,汤姆!你是最棒的!
    猜你喜欢
    • 2013-04-06
    • 1970-01-01
    • 2021-04-05
    • 2021-10-29
    • 2018-11-01
    • 1970-01-01
    • 2022-06-28
    • 1970-01-01
    • 2020-05-24
    相关资源
    最近更新 更多