Pass full source to compute_asset_host #14119

wants to merge 3 commits into


None yet
6 participants

dudeman commented Feb 20, 2014

Currently if the source contains a query string that string is not available when computing the asset host.
This commit merges the the tail back onto the source before passing it to the compute_asset_host that way any query string paramaters will be available when computing the asset host.

flevour commented Feb 20, 2014

Hi @dudeman, how "making any query string param available to compute_asset_host" would benefit the final users? A use case description would help understand this issue better!

dudeman commented Feb 20, 2014

Hi @flevour,
Sure! Having the full source available to compute_asset_host also means that full source is available to a configured ActionController::Base.config.asset_host proc. This allow you to vary the asset host based on params in the query string of the source.

For example:
If you're importing production data into your staging environment, you may need images created in staging to be on your staging host, while images created in production are served on your production host. Adding a query string and looking for that in your asset_host proc is one way to do that.
Some example code, assuming a system where you let users upload a profile photo, stored on s3, and then import those profiles into your staging environment for testing.

# app/helpers/user_helper.rb
module UserHelper
  def profile_image_path(profile)
    profile.staging_upload? ? "#{profile.image_path}?staging=true" : profile.image_path

# config/environments/staging.rb
  config.action_controller.asset_host = do |source, request|
    staging_upload = source =~ /staging=true/
    if staging_upload 
      // return staging asset host
      // production asset host

# app/views/user/profile.html.erb
<%= image_tag profile_image_url(profile) %>

Also, it's worth noting that this is how it used to behave in Rails 2 and 3. The full source had always been available to compute_asset_host (and the asset_host proc if you have one) until Rails 4.

robin850 added the actionview label Feb 23, 2014


matthewd commented Apr 19, 2014

@dudeman this sounds pretty reasonable. Could you please add a test case to ensure this doesn't go away again?

dudeman commented Apr 20, 2014

Happily. I've added a test, does that look good to you @matthewd ?


arunagw commented Jan 9, 2015

So this PR needs a rebase with master.

sgrif was assigned by rails-bot Oct 20, 2015

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