Skip to content

Commit

Permalink
fix active storage links for attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
mortbauer committed Feb 16, 2024
1 parent a7290f7 commit 3605298
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 5 deletions.
5 changes: 5 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ class ApplicationController < ActionController::Base
after_action :remove_controller
around_action :set_time_zone, :set_currency

# needed for linking to attachments on locals storage

Check failure on line 14 in app/controllers/application_controller.rb

View workflow job for this annotation

GitHub Actions / test

Layout/TrailingWhitespace: Trailing whitespace detected.
before_action do
ActiveStorage::Current.url_options = { protocol: request.protocol, host: request.host, port: request.port }
end

# Returns the controller handling the current request.
def self.current
Thread.current[:application_controller]
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/users/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- f.object.attachments.reject(&:new_record?).each do |attachment|
.controls.control-text{id: "attachment_#{attachment.id}"}
= f.hidden_field :attachments, value: attachment.signed_id, multiple: true
= link_to url_for(attachment), target: "_blank" do
= link_to attachment.url, target: "_blank" do
= image_tag attachment.preview(resize_to_limit: [100, 100]) if attachment.previewable?
= image_tag attachment.variant(resize_to_limit: [100, 100]) if attachment.variable?
= link_to 'Delete', delete_attachment_finance_invoice_path(f.object, attachment_id: attachment.id), method: :delete, remote: true, class: 'btn'
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/users/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
%dt= heading_helper User, :attachment
- for attachment in @user.attachments
%dd
=link_to url_for(attachment), target: "_blank" do
=link_to attachment.url, target: "_blank" do
= image_tag attachment.preview(resize_to_limit: [100, 100]), style: 'margin: 0px 10px 10px 0px;' if attachment.previewable?
= image_tag attachment.variant(resize_to_limit: [100, 100]), style: 'margin: 0px 10px 10px 0px;' if attachment.variable?
= attachment.filename
Expand Down
2 changes: 1 addition & 1 deletion app/views/finance/invoices/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
- f.object.attachments.reject(&:new_record?).each do |attachment|
.controls.control-text{id: "attachment_#{attachment.id}"}
= f.hidden_field :attachments, value: attachment.signed_id, multiple: true
= link_to url_for(attachment), target: "_blank" do
= link_to attachment.url, target: "_blank" do
= image_tag attachment.preview(resize_to_limit: [100, 100]) if attachment.previewable?
= image_tag attachment.variant(resize_to_limit: [100, 100]) if attachment.variable?
= link_to 'Delete', delete_attachment_finance_invoice_path(f.object, attachment_id: attachment.id), method: :delete, remote: true, class: 'btn'
Expand Down
2 changes: 1 addition & 1 deletion app/views/finance/invoices/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
%dt= heading_helper(Invoice, :attachment) + ':'
- for attachment in @invoice.attachments
%dd
=link_to url_for(attachment), target: "_blank" do
=link_to attachment.url, target: "_blank" do
= image_tag attachment.preview(resize_to_limit: [100, 100]), style: 'margin: 0px 10px 10px 0px;' if attachment.previewable?
= image_tag attachment.variant(resize_to_limit: [100, 100]), style: 'margin: 0px 10px 10px 0px;' if attachment.variable?
= attachment.filename
Expand Down
2 changes: 1 addition & 1 deletion app/views/finance/invoices/unpaid.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
= number_to_currency(invoice_amount_diff.abs)
- if invoice.attachments.attached?
- for attachment in invoice.attachments
= link_to attachment.filename, url_for(attachment)
= link_to attachment.filename, attachment.url
= glyph :download
- if invoice.note?
= '(' + invoice.note + ')'
Expand Down

0 comments on commit 3605298

Please sign in to comment.