Reputation: 5622
I want to render json similar to:
{
success:0,
error:"No money specified";
}
Now I can do this in a seperate view, but i was wondering if there is any way of directly showing this json and bypassing the biew. On a related note, can i directly dump a string to ouput(instead of the view) in rails. I am using 4.0, but should be generic enough
Upvotes: 0
Views: 91
Reputation: 413
Use the following line directly in your controller
render :json => {success: 0, error: "No money specified"}
For more on this, you can look at the doc for respond_to: http://api.rubyonrails.org/classes/ActionController/MimeResponds.html
Upvotes: 3