Rails:未指定标题时显示图像和图像大小的 Trix 编辑器

Pro*_*ton 2 ruby-on-rails trix actiontext

我正在使用 Ubuntu 18 开发Rails 6 应用程序。

我刚刚为 Trix 编辑器安装了ActionText(所见即所得),这样我就可以将文本保存到可由管理员修改的数据库中,但是,当我使用Trix编辑器添加图像时,如果我不这样做t 指定图像的标题,它将图像名称大小显示为标题

我只是想删除字幕,并且只有当我自己指定字幕时才会有字幕。

Pro*_*ton 7

后来我想出了怎么做。

成功安装ActionText后:

rails action_text:install
Run Code Online (Sandbox Code Playgroud)

并成功设置:

// application.js
require("trix")
require("@rails/actiontext")

// actiontext.scss
@import "trix/dist/trix";
Run Code Online (Sandbox Code Playgroud)

修改这些代码行app/views/active_storage/blobs/_blob.html.erb

<span class="attachment__name"><%= blob.filename %></span>
<span class="attachment__size"><%= number_to_human_size blob.byte_size %></span>
Run Code Online (Sandbox Code Playgroud)

对此

<span class="attachment__name"><% blob.filename %></span>
<span class="attachment__size"><% number_to_human_size blob.byte_size %></span>
Run Code Online (Sandbox Code Playgroud)

即去掉=这两行代码中的符号,这样在不指定标题的情况下,图像的名称大小就不会显示为标题。

就这样。

我希望这有帮助