Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've tried your configuration, but when I use <code>config.action_controller.asset_host = "assets.myserver.com"</code> in my <code>development.rb</code> <code>image_tag</code> works as expected:</p> <pre><code>&lt;img alt="Header" src="http://assets.myserver.com/assets/header.jpg" /&gt; </code></pre> <p>I've tested it both under Rails 3.2.7 and 3.2.8, but it works in both versions.</p> <p><strong>UPDATE</strong></p> <p>In my original answer I didn't use the <code>rails-api</code> gem. When using the <code>rails-api</code> gem <code>image_tag</code> works as described in the question.</p> <p>Well to answer the actual question, you could add an initializer in <code>config/initializers</code>. Just create a file, lets say <code>image_tag_helper.rb</code>, with the following code:</p> <pre><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 </code></pre> <p>What this basically does is reopening the module and replace the <code>image_tag</code> method with your own method. All other methods within the <code>module AssetTagHelper</code> remain the same. Take a look at the Rails <a href="https://github.com/rails/rails/blob/e826a5c749f9a4029a3b2a7e3d371498feeb9b10/actionpack/lib/action_view/helpers/asset_tag_helper.rb#L356" rel="nofollow">repository at github</a> for a complete 'example' of the <code>image_tag</code> method.</p> <p>The name of the file doesn't really matter. All files within <code>config/initializers</code> are loaded when the application is booted.</p> <p>Basically this is a language feature of Ruby, Ruby allows you to reopen classes everywhere in your code and add or replace methods (you find more on this subject at <a href="http://rubylearning.com/satishtalim/ruby_overriding_methods.html" rel="nofollow">rubylearning.com</a>).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload