Rails: Render Json Status Problems

You have created the json there, which will be returned, and in that json will be an identification of the status – 400. However, that’s not telling Rails to send the 400 status in the header.

You could do:

render json: {
  error: "No such user; check the submitted email address",
  status: 400
}, status: 400

Or something like

payload = {
  error: "No such user; check the submitted email address",
  status: 400
}
render :json => payload, :status => :bad_request

You can use either the symbol :bad_request or the status number 400.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)