Skip to content

Commit

Permalink
Rewrite attachment previewing
Browse files Browse the repository at this point in the history
- Utilise Active Storage previews and variants
- Resize attachment previews to 300x300>
- Render download button if not previewable
- Display filename
- Link to paths instead of URLs

Thanks @tachyons
  • Loading branch information
richardvenneman committed Oct 4, 2018
1 parent fed1723 commit bbbd3e9
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions app/views/trestle/active_storage/_field.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
<div class="active-storage">
<% if attachment.attached? %>
<div class="active-storage__preview">
<% if attachment.blob.image? %>
<%= link_to image_tag(main_app.rails_blob_url(attachment), class: 'active-storage__image'),
main_app.rails_blob_url(attachment), target: 'blank' %>
<% if attachment.previewable? %>
<%= link_to image_tag(main_app.url_for(attachment.preview(resize: "300x300>")), class: "active-storage__image"),
main_app.rails_blob_path(attachment, disposition: "attachment") %>
<% elsif attachment.variable? %>
<%= link_to image_tag(main_app.url_for(attachment.variant(resize: "300x300>")), class: "active-storage__image"),
main_app.rails_blob_path(attachment, disposition: "attachment") %>
<% else %>
<%= link_to(main_app.rails_blob_url(attachment), class: 'active-storage__link') %>
<%= link_to main_app.rails_blob_path(attachment, disposition: "attachment"), class: "btn btn-info" do %>
<i class="fa fa-download"></i>
<span class="btn-label">Download <%= field_name %></span>
<% end %>
<% end %>
<div><small><%= attachment.blob.filename %></small></div>
</div>

<%= builder.check_box("delete_#{field_name}", label: "Delete #{field_name}") %>
Expand Down

0 comments on commit bbbd3e9

Please # to comment.