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

Decouple config.asset_host assignment from rails: #415

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Edouard-chin
Copy link
Member

@Edouard-chin Edouard-chin commented Nov 29, 2017

Decouple config.asset_host assignment from rails:

  • 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:
    2. If a gem decide to set the asset_host automatically for any apps, the gem can do so inside an initializer.
        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

- 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
@rails-bot
Copy link

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.

@rafaelfranca
Copy link
Member

This is actually coupling more sprockets-rails to rails. I think the real problem is that the config used to configure the sprockets environment is the config at the block definition time https://github.com/rails/sprockets-rails/blob/master/lib/sprockets/railtie.rb#L135, not the config in the after_initialize. Try to pass the config a second argument when executing the block here https://github.com/rails/sprockets-rails/blob/master/lib/sprockets/railtie.rb#L179

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants