I built a json view to return json in one of ajax call in rails4 app. I have used the idea suggested here https://stackoverflow.com/a/12832116/1560470
But I always
I had the same issue, I found success with a call to render followed by whatever status you want to issue. At the bottom of create
put the following
render status: 400
Reference: https://stackoverflow.com/a/28144206/3826642
You can move the logic from that envelope method to the jbuilder template so you're passing status directly from controller to the view.
That status you have in the envelope method will only be in the json that is rendered, it's not a http response status code sent by the server whereas as the one in the render method is