Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forcing HTTP Response to return Status 200 in Rails

How do you force your requests to return status 200 except for serious cases where I return 500? Currently, I am running into the issue where my client keeps getting a status code of 411 (length not specified) and this is causing issues with my test framework.

Is there a way to manually specify your return status in maybe a Rails controller?

EDIT: More specifically I know that you can use

:status

but where do I place that when using

format.json { render :json=>final_obj}

to return a HTTP response after a POST?

like image 600
user1431282 Avatar asked Feb 11 '13 05:02

user1431282


2 Answers

render status: 200, json: @controller.to_json
like image 119
xdsemx Avatar answered Oct 22 '22 17:10

xdsemx


I suppose this should answer your question, if I understood your question correctly.

Ruby 1.9.3

format.json { render json: final_obj, status: :ok }

Ruby 1.8.7

format.json { render :json => final_obj, :status => :ok }
like image 34
Peter de Ridder Avatar answered Oct 22 '22 16:10

Peter de Ridder