Rails4 jbuilder always return status code 200, even if I put other status code

前端 未结 1 2028
栀梦
栀梦 2021-01-15 18:54

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

相关标签:
1条回答
  • 2021-01-15 19:28

    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

    0 讨论(0)
提交回复
热议问题