Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow ActiveStorage.default_url_options for DiskService #42847

Closed
wants to merge 4 commits into from

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
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 2 times, most recently from 4663668 to 9f13748 Compare July 31, 2021 16:12
@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
@@ -160,7 +160,7 @@ def url_helpers
end

def url_options
ActiveStorage::Current.url_options
ActiveStorage::Current.url_options || Rails.application.routes.default_url_options
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 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.

None yet

2 participants