我正在尝试编辑
app/views/active_storage/blobs/_blob.html.erb
,安装active_storage时创建的部分文件,它允许您自定义blob在action_text输出中的显示方式。
在其他项目上,这没有问题,在新的 Rails 7 项目上,安装过程中添加的部分似乎被忽略,因此不会进行任何编辑。
我可以通过进行小的文本更改来看到这一点(因此不添加可能会被删除的 HTML 元素)。
例如,我在几个地方添加了“这是一个测试”,这没有显示:
app/views/active_storage/blobs/_blob.html.erb
:
<figure class="attachment attachment--<%= blob.representable? ? "preview" : "file" %> attachment--<%= blob.filename.extension %>">
<% if blob.representable? %>
<%= image_tag blob.representation(resize_to_limit: local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ]) %>
<% end %>
<figcaption class="attachment__caption">
<% if caption = blob.try(:caption) %>
<%= caption %>
this is a test
<% else %>
<span class="attachment__name"><%= blob.filename %></span>
<span>this is a test</span>
<span class="attachment__size"><%= number_to_human_size blob.byte_size %></span>
<% end %>
</figcaption>
</figure>
在其他项目中,当您在开发中查看日志输出时,它会正确显示“rendered app/views/active_storage/blobs/_blob.html.erb”,但在这个项目中则不然。
文件上传通过actiontext工作,渲染文件通过内置部分工作,但我根本无法查看可定制的版本。
这种情况在开发和生产环境中都会发生,所以我不认为这是什么奇怪的急切加载/缓存问题。
有人知道我可以从哪里开始进一步调试吗?
我花了很长时间来调试这个问题,直到我意识到我认为是 Blob 附件的东西原来是“远程图像”附件。 (参见此处的源代码示例)。
虽然这在我们的测试数据中是一个奇怪的故障,但在这种情况下,Rails 会渲染
views/action_text/attachables/_remote_image.html.erb
。