Return a specific http status code in Rails

后端 未结 3 1601
无人及你
无人及你 2021-01-31 01:08

How do you return 503 Service Unavailable in Rails for the entire application?

Also, how do you do the same for specific controllers?

3条回答
  •  花落未央
    2021-01-31 01:57

    The following works for me:

    format.any { render :json => {:response => 'Unable to authenticate' },:status => 401  }
    

    The :response for the HTML response just in case it's accessed from the browser.

    The render head 503 does not seem to be working with the above statement.

提交回复
热议问题