mercredi 13 janvier 2016

How to get json response in rails api

I want to display all programmes(which i got from query) as json response. here i am getting the programmes, but how to display through json? PLease help. i have jbuilder gem. and also a create.json.buider.rb file. in query iam getting everything, but iam not getting json response as whatever details in i have in query

my controller, i tried like this ,but iam not getting json response.only i am getting status as 200

class Api::V1::Categories::ProgrammesController < ApiController respond_to :json def category @category=Category.all @programmes=Programme.joins(:category).find_by(category_id: params[:category_id]) if @programmes.present? render :json=> {:message=>"Programme not exists "}, :status=>422 else render :json => @programmes end end end

my 'create.json.jbuilder' file

json.programmes @programmes

Aucun commentaire:

Enregistrer un commentaire