title: Rails - How to render json with extra field in index controller method
body: <p>I'm using <code>Rails 4.0.2</code> with <code>paperclip</code> for image upload in my project. Also I need to send a full image path of paperclip. So I can do it with add new field and set image path manually in my <code>show</code> controller method for particular record.</p>
  
  <p><strong>show</strong></p>
  
  <pre><code>def show
    respond_to do |format| 
      format.html
      format.json { :json =&gt; JSON::parse(@demo.to_json.merge("new_field" =&gt; @demo.image_url.url).to_json}
    end
  end
  </code></pre>
  
  <p>When I view Json for any of my record, this is will showing good.</p>
  
  <pre><code>{
    id: "1",
    name: "demo",
    new_field: "/demo/1/original/file.jpg"
  }
  </code></pre>
  
  <p>In same scenario, I need to get the full image path of paperclip image for all records when I am requesting to <code>index</code> method on <code>controller</code></p>
  
  <p><strong>index</strong></p>
  
  <pre><code>def index 
    @demos = Demo.all
    respond_to do |format|
      format.html
      format.json { :json =&gt; Demo.all.to_json}
    end
  end
  </code></pre>
  
  <p>I tried some of codes, but I don't know how exactly to write</p>
  
  <pre><code>def index 
    @demos = Demo.all
    @demos.each do |demo|
       new_field = {"new_field" =&gt; @demo.image_url.url}
       # After I stucked with logic, how to uppend with 'demo'.
    end
  
    respond_to do |format|
      format.html
      format.json { :json =&gt; Demo.all.to_json}
    end
  end
  </code></pre>
  
  <p>How do I iterate my individual <code>Demo</code> model and How to merge full image path into each record.</p>