Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActionText: Link to attachment instead of preview

Is there a way for Trix editor (or ActionText) to display a link of the file attached so people could download it instead of showing a preview of the file? My example attachment is a PDF.

like image 456
konyak Avatar asked Sep 18 '25 13:09

konyak


1 Answers

You can edit it in the _blob.html.erb file, for example:

<span class="attachment__download"><%= link_to blob.filename, rails_blob_path(blob) %></span>
<span class="attachment__size"><%= number_to_human_size blob.byte_size %></span>

Because action text will use this _blob.html.erb file for rendering the attachment file you upload, you can do anything in here with object blob (ActiveStorage::Blob)

For more information

https://api.rubyonrails.org/classes/ActiveStorage/Preview.html https://edgeapi.rubyonrails.org/classes/ActiveStorage/Blob.html

like image 151
Phạm Ngọc Hoàng Avatar answered Sep 22 '25 01:09

Phạm Ngọc Hoàng