Repository navigation
Decouple config.asset_host assignment from rails: - #415
Edouard-chin wants to merge 1 commit into
Conversation
- There is two way to set the asset_host in rails: `config.action_controller.asset_host=` and `config.asset_host=` (the latter being usefull to both set action_mailer/action_controller asset_host)
- Opening this PR for two reasons:
1. Getting the asset_host from `config.action_controller` currently works when the asset_host is defined using `config.asset_host` but I feel like this might be by chance:
- When rails initialization process kicks in, the `action_controller.set_configs` initializer runs. A variable `options` is assigned and reference `config.action_controller`. The `options` variable get modified and by doing so modify the refernce to `config.action_controller` https://github.com/rails/rails/blob/1bee2fb600c07625b830afd33b43ead3364c9715/actionpack/lib/action_controller/railtie.rb#L50
2. If a gem decide to set the asset_host automatically for any apps, the gem can do so inside an initializer.
```ruby
initializer :set_asset_host do |app|
app.config.asset_host = 'https://example.com'
end
```
This code won't have any effect in sprockets-rails and as a result any assets referenced inside css, i.e. (`.div { background-image: url('/assets/rails.png') }) will not be prefixed by the asset_host
|
Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @rafaelfranca (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
|
This is actually coupling more sprockets-rails to rails. I think the real problem is that the |
Decouple
config.asset_hostassignment from rails:config.action_controller.asset_host=andconfig.asset_host=(the latter being usefull to both set action_mailer/action_controller asset_host)config.action_controllercurrently works when the asset_host is defined usingconfig.asset_hostbut I feel like this might be by chance:action_controller.set_configsinitializer runs. A variableoptionsis assigned and referenceconfig.action_controller. Theoptionsvariable get modified and by doing so modify the refernce toconfig.action_controllerhttps://github.com/rails/rails/blob/1bee2fb600c07625b830afd33b43ead3364c9715/actionpack/lib/action_controller/railtie.rb#L50.div { background-image: url('/assets/rails.png') }) will not be prefixed by the asset_host