【问题标题】:Can't Load user picture on cloudinary无法在云端加载用户图片
【发布时间】:2017-12-01 13:19:31
【问题描述】:

您好,我无法在我的网页上加载用户的图片。

cloudinary display error on web page

当我查看我的 Cloudinary 帐户时,我找不到图片。

res.cloudinary.com/di7e0fdiq/image/upload/v1498636677/rj2ijo3yb6yvmyrybnps.jpg

这是我的代码:我正在使用帮助程序来显示用户的图片。我在我的节目中称这个助手:

  def user_picture_avatar(user, image_class)
   if user.photo?
    cl_image_tag(user.photo.path, class: image_class)
   else
    avatar_url = user.linkedin_picture_url || "http://placehold.it/100x100"
    image_tag avatar_url, class: image_class
   end
  end

我直接在我的节目中测试了代码,也没有使用帮助程序,我得到了相同的结果。

<!-- avatar display using helper -->
  <div class="user-show-photo">
    <%= user_picture_avatar(current_user, "interview-show-avatar avatar-bordered-xl") %>
  </div>

  <!-- avatar display without helper -->
  <div class="user-show-photo">
    <%= cl_image_tag @user.photo.path, width: 400, height: 300, crop: :fill %>
  </div>

当我查看网页上的检查器时,我得到以下信息:

html on web page

我已经多次检查了我的 cloudinary、figaro、application.yml 和 strong params 设置,但似乎无法解决这个问题。

你能帮忙吗?

【问题讨论】:

  • 你好,user.photo.path 的值是多少,根据文档,你为什么使用路径而不是图像名称 cl_image_tag("sample.jpg", :width =&gt; 100, :height =&gt; 150, :crop =&gt; :fill)

标签: ruby-on-rails cloudinary


【解决方案1】:

查看我们的日志,我们看到图片确实是在 6 月 28 日 07:57:59 UTC 上传的(您收到带有版本号的链接也表明了这一点)

但是,我们看到它是在 UTC 时间 07:58:01 上传两秒后的 destroyed

这通常意味着错误地发出了销毁调用。

【讨论】:

  • 是的,就是这样!感谢您提供的提示,它允许我在更新功能中识别 enrouons 代码。我实际上连续更新了两次。所以在第一次更新时,图片被正确上传,然后在第二次更新时,它被销毁而没有被替换!我使用 binding.pry 进行调试,非常有用!
猜你喜欢
  • 2017-02-07
  • 1970-01-01
  • 1970-01-01
  • 2020-10-28
  • 1970-01-01
  • 2021-03-27
  • 2013-12-20
  • 1970-01-01
相关资源
最近更新 更多