# Allow Rails.application.routes.default\_url\_options for DiskService

**URL:** <https://discuss.rubyonrails.org/t/allow-rails-application-routes-default-url-options-for-diskservice/78528>\
**Category:** rubyonrails-core\
**Tags:** activestorage\
**Created:** [July 27, 2021, 8:39am UTC](https://discuss.rubyonrails.org/t/allow-rails-application-routes-default-url-options-for-diskservice/78528 "2021-07-27T08:39:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jose\_Galisteo](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/jose_galisteo/32/3771_2.png) [@Jose\_Galisteo](https://discuss.rubyonrails.org/u/Jose_Galisteo)\
**Post date:** [July 27, 2021, 8:39am UTC](https://discuss.rubyonrails.org/t/allow-rails-application-routes-default-url-options-for-diskservice/78528/1 "2021-07-27T08:39:17Z")

</div>

Hi! I created a PR that allows Rails.application.routes.default\_url\_options for DiskService.

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 || Rails.application.routes.default_url_options` as source for `url_options` . This approach allows override global `url_options` from `Rails.application.routes` with `ActiveStorage::SetCurrent` if needed.

What do you think? Thanks!

> <https://github.com/rails/rails/pull/42847>
>
> \### Summary
> 
> \`DiskService\` can use \`ActiveStorage::Current.url\_options\` or \`Ac…tiveStorage.default\_url\_options\` (in that order) as url options.
> 
> Related to: https://github.com/rails/rails/issues/40855 https://github.com/rails/rails/issues/37841 https://github.com/rails/rails/issues/33549 https://github.com/rails/rails/issues/32590 https://github.com/rails/rails/issues/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.
