Rails (3.2.7): override image_tag for asset_host

Viewed 1969

development.rb:

config.action_controller.asset_host = "assets.myserver.com"

view script:

<%= image_tag('header.jpg') %>

yields:

<img alt="Header" src="/header.jpg" />

should be:

<img alt="Header" src="http://assets.myserver.com/header.jpg" />

I am using the rails-api gem which I am guessing disables some asset and view rendering stuff.

It seems like it should not be too hard to re-implement (override image_tag) to add this very small feature. It may seem a little odd to want to do this. However, I am new-ish to rails would like to know how to do this as a learning experience.

Questions:

  1. As a best practice where should I place this new code in the file structure?
  2. What should I name the file with the new code?
  3. How does rails know to look at the new code instead of looking at the old image_tag function?
1 Answers
Related