Skip to content

Conversation

@ceritium
Copy link
Contributor

@ceritium ceritium commented Jul 22, 2021

Summary

DiskService can use ActiveStorage::Current.url_options or ActiveStorage.default_url_options (in that order) as url options.

Related to: #40855 #37841 #33549 #32590 #13372

Why

Setting ActiveStorage::Current.host or ActiveStorage::Current.url_options is useful when generate the URLs from ActionController. But if you need to generate the URLs in a background job or rake task, it seems cumbersome to have to define it in another place. Also for my experience can be a bit confusing to other developers.

I think that we can use ActiveStorage::Current.url_options || ActiveStorage.default_url_options as source for url_options. This approach allows override global ActiveStorage.default_url_options with ActiveStorage::SetCurrent if needed.

Other Information

If the PR receives positive feedback, I will update the guidelines in this or another PR.

@ceritium ceritium force-pushed the disk-usage-url-options branch from ab78bdd to 58b84ae Compare July 23, 2021 08:09
@ceritium
Copy link
Contributor Author

ceritium commented Jul 23, 2021

I think that the failing test is not because of my commits. Maybe it is related #42845

Edit: The PR #42845 was merged, and the issue is fixed after rebase.

@ceritium ceritium force-pushed the disk-usage-url-options branch from 58b84ae to 79a28a3 Compare July 23, 2021 18:10
@ceritium ceritium force-pushed the disk-usage-url-options branch 2 times, most recently from 4663668 to 9f13748 Compare July 31, 2021 16:12
@ceritium ceritium force-pushed the disk-usage-url-options branch from 9f13748 to 1bb7ca6 Compare August 26, 2021 09:13
@rails-bot
Copy link

rails-bot bot commented Dec 2, 2021

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contributions.

@rails-bot rails-bot bot added the stale label Dec 2, 2021
@rails-bot rails-bot bot closed this Dec 9, 2021
@rafaelfranca rafaelfranca reopened this Dec 9, 2021
@rails-bot rails-bot bot removed the stale label Dec 9, 2021
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Active Storage should not depend on the Rails application. Maybe we should inject it into the DiskService using the Engine in Active Storage?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3b0556e, It is what you mean? Let me know what you think.

DiskService can use ActiveStorage::Current.url_options
or Rails.application.routes.default_url_options (in that order) as url
options.
@ceritium ceritium force-pushed the disk-usage-url-options branch 2 times, most recently from fb1d2e4 to 2b9bdcc Compare December 14, 2021 07:34
@ceritium ceritium force-pushed the disk-usage-url-options branch from 2b9bdcc to 4299ae2 Compare December 14, 2021 08:06
@ceritium ceritium changed the title Allow Rails.application.routes.default_url_options for DiskService Allow ActiveStorage.default_url_options for DiskService Dec 14, 2021
@rails-bot
Copy link

rails-bot bot commented Mar 14, 2022

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants