title: How to add virtual attributes to API json response
body: <p><strong>Context</strong>: ruby "2.0.0" and rails "4.0.0"</p>
  
  <p>I am wondering how to return more data than a simple JSON representation of my model. I have this method in my API controller:</p>
  
  <pre><code>def show
    @entry = params[:id].to_i != 0 ? Entry.find(params[:id]) : Entry.where(slug: params[:id]).first
    respond_with @entry
  end
  </code></pre>
  
  <p>which returns a well formatted JSON article when called via <code>http://pow.url.dev/en/tenant/api/v1/entries/23</code>.</p>
  
  <p>I also have two other method to get the next and previous article, for instance, <code>next</code> looks like this:</p>
  
  <pre><code>def next
    @current_entry = params[:entry_id].to_i != 0 ? Entry.find(params[:entry_id]) : Entry.where(slug: params[:entry_id]).first
    @entry = Entry.where( status_id: 0 ).where( "published_at &gt; ?", @current_entry.published_at ).first
    respond_with @entry
  end
  </code></pre>
  
  <p>The problem is that the client application needs to make 3 API calls to <em>1) fetch an article, 2) fetch the next article and 3) fetch the previous article.</em></p>
  
  <p>It would be much better if the client had to do only one call to get all the information at once.</p>
  
  <p>I would like to add into the <code>show</code> method the <strong>Title and ID</strong> of the next and previous article along with the JSON result, what would be the best way to do that?</p>