title: Rails 4 - Customizing (json) format of response objects in Rails
body: <p>I have a Rails Controller who responds with JSON objects. Let's take this theoretical example : </p>
  
  <pre><code>respond_to :json
  def index 
    respond_with Comment.all
  end
  </code></pre>
  
  <p>This would respond with something like </p>
  
  <pre><code>[{"id":1,"comment_text":"Random text ", "user_id":1  ,"created_at":"2013-07-26T15:08:01.271Z","updated_at":"2013-07-26T15:08:01.271Z"}]
  </code></pre>
  
  <p>What i'm looking for is a "best practice" method to interfere with the formating of the json object and return something like this : </p>
  
  <pre><code>[{"id":1,"comment_text":"Random text ", "username": "John Doe", "user_id":1  ,"created_at":"3 hours ago"}]
  </code></pre>
  
  <p>As you can see, i'm adding a column that doesn't exist in the database model "username" , i'm taking out "updated_at" , and i'm formatting "created_at" to contain human readable text rather than a date. </p>
  
  <p>Any thoughts anyone ? </p>