Using process_host proc for image only in Rails 3.1

In previous versions of rails, I was able to use proc to serve only image objects from another server with:

ActionController::Base.asset_host = Proc.new { |source|
  if source.starts_with?('/images')
   "https://s3.amazonaws.com/..."
  end
}

This does not seem to work in Rails 3.1 due to the new asset pipeline. Does anyone know how to do this?

+5
source share
1 answer

This seems to be a hack, but it works:

  config.action_controller.asset_host = Proc.new { |source|
    if source =~ /\b(.png|.jpg|.gif)\b/i
      "https://s3.amazonaws.com/bucketName"
    end
  }

The folder should be named assets inside this bucket, not images.

+7
source

All Articles