Active Storage _blob 部分未得到尊重或加载
我正在尝试编辑 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工作,渲染文件通过内置部分工作,但我根本无法查看可定制的版本。
这种情况在开发和生产环境中都会发生,所以我不认为这是什么奇怪的急切加载/缓存问题。
有谁知道我可以从哪里开始进一步调试这个问题?
- 导轨:7.0.2.3
I am trying to edit app/views/active_storage/blobs/_blob.html.erb
, the partial file created when installing active_storage which allows you to customise how blobs appear inside action_text output.
On other projects, this has worked without issue, on a new Rails 7 project it would appear that the partial added during install is being ignored, as such no edits are coming through.
I can see this by making a small text change (so not adding an HTML element which may get stripped).
For example, I've added "this is a test" in a few places, this does not show:
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>
In other projects, when you view the log output in development it will correctly say "rendered app/views/active_storage/blobs/_blob.html.erb", on this project it doesn't.
File uploads work via actiontext, and rendering the file works by way of the built-in partial, but I can't get the customisable version to be viewed at all.
This is happening on both development and production environments, so I don't think it is anything like a weird eager loading/caching issue.
Does anyone have any ideas as to where I could start looking to debug this further?
- rails: 7.0.2.3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我花了很长时间来调试它,直到我意识到我认为是 Blob 附件的东西原来是“远程图像”附件。 (参见源代码示例)。
虽然这是我们的测试数据中的一个奇怪的故障,但 Rails 渲染了
views/action_text/attachables/_remote_image.html.erb
。I spent a long time to debug this until I realized that what I thought was a blob attachment turned out to be a "remote image" attachment. (Seen in source code for example here).
While this was a weird glitch in our test data, Rails renders
views/action_text/attachables/_remote_image.html.erb
in this case instead.