【发布时间】:2020-07-08 16:59:42
【问题描述】:
我目前正在开发一个使用 cloduinary 托管图像的 Rails 6 应用程序。我有一个rich_text_content 的模型。
class Question < ApplicationRecord
belongs_to :user
has_many :comments, as: :commentable
has_rich_text :content
end
当我从富文本编辑器添加图像并尝试呈现图像时,浏览器不会呈现附加图像。
意见/问题/show.html.erb
<div class="border-t-2 border-gray-600 text-2xl m-auto w-4/5">
<div class="h-56 my-8">
<%= @question.content %>
</div>
</div>
show.html.erb 模板仅显示文本内容而不显示 @question.content 中的附件图像,因此当有 embeds_blob 时,_blob.html.erb 不会显示图像。
<figure class="attachment attachment--<%= blob.representable? ? "preview" : "file" %> attachment--<%= blob.filename.extension %>">
<% if blob.representable? %>
<div class="max-w-xl mx-auto rounded overflow-hidden shadow-lg">
<%= cl_image_tag(blob.key, format: :jpg )%>
<div class="px-6 py-4">
<figcaption class="attachment__caption">
<% if caption = blob.try(:caption) %>
<%= caption %>
<% else %>
<div class="inline-block bg-gray-200 rounded-full px-3 py-1 text-sm font-semibold text-gray-700 mr-2">
<span class="attachment__name"><%= blob.filename %></span>
<span class="attachment__size"><%= number_to_human_size blob.byte_size %></span>
</div>
<% end %>
</figcaption>
</div>
</div>
<% end %>
</figure>
cl_image_tag(blob.key, format: :jpg) 应该正在渲染附件文件,但它没有如下图所示
但是,如果我要评论所有内容并且只有以下行。 <%= cl_image_tag(blob.key, format: :jpg )%>。该图像是在没有来自_blob.html.erb 的 HTML 结构的情况下呈现的。
为什么_blob.html.erb 不渲染来自 Cloudinary 的附加图像?
【问题讨论】:
标签: ruby-on-rails rails-activestorage ruby-on-rails-6 actiontext