I tried your configuration, but when I use config.action_controller.asset_host = "assets.myserver.com"
in my development.rb
image_tag
works as expected:
<img alt="Header" src="http://assets.myserver.com/assets/header.jpg" />
I tested it in both Rails 3.2.7 and 3.2.8, but it works in both versions.
UPDATE
In my original answer, I did not use the rails-api
gem. When using rails-api
gem image_tag
works as described in the question.
To answer the real question, you can add an initializer in config/initializers
. Just create a file, say image_tag_helper.rb
, with the following code:
# config/initializers/image_tag_helper.rb module ActionView module Helpers module AssetTagHelper def image_tag(source, options = {}) options[:src] = "http://#{source}" tag("img", options) end end end end
Basically this is reopening the module and replacing the image_tag
method with your own method. All other methods in module AssetTagHelper
remain unchanged. Take a look at the Rails repository on github for a complete βexampleβ image_tag
method.
The name of the file does not really matter. All files in config/initializers
are loaded when the application loads.
This is basically a Ruby language feature, Ruby allows you to re-open classes in your code and add or replace methods (you'll find more on this topic at rubylearning.com ).
source share