Reputation: 331
I am using pretty_generate in my controller, but I am getting the following error
'only generation of JSON objects or arrays allowed'
@celebrities = Celebrity.includes(:category)
respond_to do |format|
format.json { render json: JSON.pretty_generate(@celebrities.to_json(:include =>{:category => {:only => [:category]} })) }
end
I am not sure why I am getting this error
Upvotes: 4
Views: 3477
Reputation: 2672
As the error suggest, only generation of JSON objects or arrays allowed
. I guess you should try this.
@celebrities = Celebrity.includes(:category)
respond_to do |format|
format.json { render json: JSON.pretty_generate(JSON.parse(@celebrities.to_json(:include =>{:category => {:only => [:category]} })))}
end
Upvotes: 3