Closed jankeesvw closed 3 years ago
I found a workaround. When I use the url_for
helper it gets the right URL. This issue is probably not caused by Turbo so I'm going to close it.
This works:
<%= image_tag url_for(vehicle.image_with_fallback.variant(resize_to_fill: [424, 220])) %>
This yields:
http://stekker.test/rails/active_storage/representations/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBKQT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--cb6db5fb76e9c8fc3e226d7d8eff69917a35d5ee/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCem9MWm05eWJXRjBTU0lKYW5CbFp3WTZCa1ZVT2hOeVpYTnBlbVZmZEc5ZlptbHNiRnNIYVFLb0FXa0IzQT09IiwiZXhwIjpudWxsLCJwdXIiOiJ2YXJpYXRpb24ifX0=--b0a6e29b924216f0f5dcb59d63681f10c84e9994/ev-database.jpeg
This doesn't work
<%= image_tag vehicle.image_with_fallback.variant(resize_to_fill: [424, 220]) %>
This yields:
http://example.org/rails/active_storage/representations/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBKQT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--cb6db5fb76e9c8fc3e226d7d8eff69917a35d5ee/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCem9MWm05eWJXRjBTU0lKYW5CbFp3WTZCa1ZVT2hOeVpYTnBlbVZmZEc5ZlptbHNiRnNIYVFLb0FXa0IzQT09IiwiZXhwIjpudWxsLCJwdXIiOiJ2YXJpYXRpb24ifX0=--b0a6e29b924216f0f5dcb59d63681f10c84e9994/ev-database.jpeg
@jankeesvw I can confirm the workaround for direct attachments, but the problem is compounded with the use of ActionText. You don't have control over building the URL in that scenario... or at least not in any obvious way that I could find. Did you determine the culprit if not Turbo?
No, sorry. I'm just using url_for
right now.
I suspect this is caused when an asset_host
is defined. In that case an image_tag
would link to an absolute url with the asset host by default. When an attachment is passed instead it seems to want to still build an absolute url and looks for that at config.action_controller.default_url_options
or uses example.com
if that's not set. Ideally because it's a local route it should be a relative url. Perhaps this is a bug?
Setting config.action_controller.default_url_options
may have side effects to your project, which you don't expect. url_for
is a solution for me too without changing global configuration, which change routing behaviour in some unexpected way for me.
As all related issues and pull-requests were closed due to inactivity, there is no good solution for this issue except these two workarounds.
I've written a blog post regarding Default URL Options to better understand the different settings, which might be the reason tool.
The analysis of my problems with ActiveStorage are documented here: Define Default URL for ActiveStorage to fix Mixed Content Error
Confirming this is still an issue that can cause active storage to redirect to example.org.
Same; having this issue with ActsAsTenant, ActiveJob, ActiveStorage ....
Same; having this issue with ActsAsTenant, ActiveJob, ActiveStorage ....
Try to check the different settings you have in your project. If you set the wrong configuration/param, they will have side effects on other parts of your application like ActiveJob, ActiveStorage, etc. Check my blog post, where the setup for ActiveStorage etc is explained: Default URL Options.
I had the same problems with ActiveStorage and tried to explain it here: Define Default URL for ActiveStorage to fix Mixed Content Error
While I am porting my application to Turbo, I run into an issue.
This is the code I've got so far:
The .erb template:
In my model:
This all seems to work great, except for one thing, the image I had in the DOM uses the wrong host after it's being replaced. The initial load uses the right URL, but when it's replaced by a broadcast it changes to example.org.
I also created this initializer:
I hope you have any idea what the solution could be, thanks!