【问题标题】:Get Cloudinary image URL获取 Cloudinary 图像 URL
【发布时间】:2016-07-12 01:56:20
【问题描述】:

我有一个名为 Tile 的模型,它有附件: has_attachment :image_attachment

我可以使用cl_image_tag @tile.image_attachment.path 显示 img 标签,但我只想获取完整的 URL 嵌入是内联样式的背景图像,有没有办法获取完整的 URL?

``@tile.image_attachment.path 返回 v1458814322/bgo1zuv4kji17f58x5m5.jpg

【问题讨论】:

    标签: ruby-on-rails ruby cloudinary


    【解决方案1】:

    你只需要使用cl_image_path(@tile.image_attachment)

    【讨论】:

      【解决方案2】:

      如果您想在视图文件之外的其他地方访问 URL:

      options = {width: 50, height: 50, crop: :fill}
      Cloudinary::Utils.cloudinary_url(image_id, options)
      

      【讨论】:

      • 拯救我的一天。谢谢。它对我的 Ruby 项目非常有用。
      猜你喜欢
      • 1970-01-01
      • 2021-03-30
      • 2017-02-24
      • 2020-03-02
      • 2021-09-15
      • 2018-02-08
      • 2019-01-26
      • 2018-04-29
      • 2021-02-04
      相关资源
      最近更新 更多