【问题标题】:How to display images from Cloudinary/attachinary如何显示来自 Cloudinary/attachinary 的图像
【发布时间】:2019-01-10 00:19:46
【问题描述】:

我目前正在研究一种从 Cloudinary 显示图像的方法。这些图像附加到Declaration model

这是我想出的:

<% cache @declarations do %>
  <table class="tableau_stats">
    <th>IMEI</th>
    <th>Prénom</th>
    <th>Nom</th>
    <th>Adresse</th>
    <th>Code postal</th>
    <th>Ville</th>
    <th>Email</th>
    <th>Numéro de téléphone</th>
    <th>Créé le</th>
    <th>Panne</th>
    <th>MDP Icloud</th>
    <th>MDP</th>

    <% @declarations.each do |declaration| %>
      <tr>
        <td><%= declaration.imei %></td>
        <td><%= declaration.firstname %></td>
        <td><%=declaration.lastname%></td>
        <td><%=declaration.address %></td>
        <td><%=declaration.postal_code %></td>
        <td><%=declaration.city%></td>
        <td><%= declaration.email %></td>
        <td><%= declaration.phone_number %></td>
        <td><%= declaration.created_at.strftime("%d.%m.%Y") %></td>
        <td><%= declaration.type_outage %></td>
        <td><%= declaration.icloud_password %></td>
        <td><%= declaration.unlock_code %></td>
        <td><%= cl_image_path(declaration.facture) %></td>
      </tr>
    <% end %>
  </table>
<% end %>

但我只有一张破损的图片和下面的链接。

根据 figaro gems,我的 ENV 存储在我的 application.yml 中。

我做错了什么?

谢谢。

更新

这就是它给我的回报

http://res.cloudinary.com/prs/image/upload/%23%3CAttachinary::File:0x00007f9dd2130408%3E

我的declaration.rb 看起来像这样:

class Declaration < ApplicationRecord
  has_attachment :facture, accept: [:pdf]
  validates_size_of :facture, maximum: 15.megabytes, message: "Le fichier doit être inférieur à 15 megabytes"
  validates :facture, presence: true
end

【问题讨论】:

  • 能否添加生成的图片标签的源代码?
  • 是的,我会编辑我的问题。
  • 像@MrShemek 这样看起来更好吗?

标签: ruby-on-rails cloudinary


【解决方案1】:

您没有指定如何在声明对象中定义 facture,但看起来 Rails 认为它​​是一个 Attachinary::File 对象。

cl_image_path(declaration.facture.path) 会更适合你吗?

【讨论】:

  • 嗨@Scott,感谢您的回答。我会在几分钟内更新我的问题。但是您的建议仍然无效:/ 我的回报与我发布的相同。
  • 嗯。查看 Cloudinary 助手内部,无论您作为第一个参数传入什么,都会调用 #to_s,这就是当您将整个对象传递给它时导致 #&lt;Attachinary::File:0x00....&gt; 输出的原因。我正在查看我自己的代码库(其中成员有一个由 Cloudinary 提供支持的 avatar 属性),而 cl_image_path(member.avatar) 会生成与您报告的相同的“错误”URL 格式。但是,cl_image_path(member.avatar.path) 是一种享受。
  • 嗯,我明白了。谢谢你的解释。但我只是注意到了一些事情。我的声明模式中没有facture 属性,所以factures 没有链接到任何声明对象..
猜你喜欢
  • 2017-02-26
  • 2017-11-21
  • 2018-06-04
  • 2015-05-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-13
  • 2021-02-20
相关资源
最近更新 更多