title: How can I use Rails image_url helper on the Controller layer so that it returns the correct value?
body: <p>I am trying to call <code>image_url</code> (from the <code>ActionView::Helpers::AssetUrlHelper</code> module) from within a controller. My controller is an API controller that renders a json response. So, the controller prepares the object and I am using <code>jBuilder</code> to render the actual JSON response. Here is the code:</p>
  
  <pre><code>class Api::Mobile::HomeController &lt; Api::Mobile::ApplicationController
    include ActionView::Helpers::AssetUrlHelper
  
    def index
      @items = [Api::Mobile::HomePageItem.new(
                  type: 'image',
                  image: image_url("api/mobile/home/tutor-with-student.jpg"))]
    end
  end
  </code></pre>
  
  <p>The image <code>tutor-with-student.jpg</code> exists in the following folder:</p>
  
  <pre><code>app/assets/images/api/mobile/home/tutor-with-student.jpg
  </code></pre>
  
  <p>The problem is that the <code>image_url</code> returns the value:</p>
  
  <pre><code>http://myhost.com/images/api/mobile/home/tutor-with-student.jpg
  </code></pre>
  
  <p>instead of</p>
  
  <pre><code>http://myhost.com/assets/api/mobile/home/tutor-with-student.jpg
  </code></pre>
  
  <p>Note that when I am using the <code>image_url</code> from the actual view, the method returns the correct value.</p>
  
  <p>How can I use the <code>image_url</code> method on the Controller layer so that it returns the correct value?</p>