Reputation: 503
I am trying to deal with the issue of uploading files which are not images with Action Text and make them functional for a user viewing the post. E.g. if there is a PDF uploaded when creating some content, the user should be able to download.
Right now my images are uploading fine and displaying fine, but if I have uploaded a PDF, it displays back the file name and size:
Bla.pdf 635 KB. It looks like this is and is not clickable:
The html beneath this is:
<action-text-attachment sgid=”BAh7CEkiCGdpZAY6BkVUSSI4Z2lkOi8vdGFhYWxrLWVkZ2UvQWN0aXZlU3RvcmFnZTo6QmxvYi82OD9leHBpcmVzX2luBjsAVEkiDHB1cnBvc2UGOwBUSSIPYXR0YWNoYWJsZQY7AFRJIg9leHBpcmVzX2F0BjsAVDA= — 9fc1638e6a6bca562cbff92f1627dfcf9e74f198" content-type=”application/pdf” url="http://localhost:3000/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBTUT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--5da8c8c82a642f3ed3f0c158a2560a7a41b974c7/Bla.pdf" filename=”Bla.pdf” filesize=”649993"><figure class=”attachment attachment — file attachment — pdf”>
<figcaption class=”attachment__caption”>
<span class=”attachment__name”>Bla.pdf</span>
<span class=”attachment__size”>635 KB</span>
</figcaption>
</figure></action-text-attachment>
Any ideas how I can make this downloadable?
Thank you
Upvotes: 3
Views: 1303
Reputation: 51
You need to change
app/views/active_storage/blobs/_blob.html.erb
like this one
<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 ]) %>
<figcaption class="attachment__caption">
<% if caption = blob.try(:caption) %>
<%= caption %>
<% else %>
<span class="attachment__name"><%= blob.filename %></span>
<span class="attachment__size"><%= number_to_human_size blob.byte_size %></span>
<% end %>
</figcaption>
<% else %>
<%= link_to blob.filename, rails_blob_path(blob) %>
<% end %>
</figure>
Upvotes: 5