Showing posts with label JSON API. Show all posts
Showing posts with label JSON API. Show all posts

Tuesday, 30 April 2013

Customizing JSON API to return few records

just Add the following method in to the Model ...
def as_json(options = {})
    {
      name: self.name,                # Whatever you want to show
      city: self.city,
      country: self.country,
      customer_id: self.customer_id
   
         }
  end
--------------------------OR---------------------------------------
you can call the .select method in the API controller
like
class Api::V1::YoursController < ApplicationController
  def show
  @your = Your.select('one, two').find(params[:id])
  respond_to do |format|
        format.json {render :json => @your}
        format.xml {render :xml => @your}
    end
 end
end