Given a classic controller action. Have a look at the MARK. I need to set the status code to 200 for the response. Background: swfupload an ajax file upload solution seems to send data in a wrong format.
I tried response.headers[‘Status’] = 200, response.status 200, render :json => ‘data’, :status => 200. But the response’s status code doesn’t change.
def create
if params[:Filedata]
@medium = Medium.new(:swf_uploaded_data => params[:Filedata])
else
@medium = Medium.new(params[:medium])
end
respond_to do |format|
if @medium.save
format.html { redirect_to(@medium, :notice => 'Medium was successfully created.'); }
format.xml { render :xml => @medium, :status => :created, :location => @medium; }
MARK
else
format.html { render :action => "new" }
format.xml { render :xml => @medium.errors, :status => :unprocessable_entity }
end
end
end
The status code can only be declared within the return commands like render, redirect_to …. and will affect to this return command, there is no way to set the code for all the responses
For
format.html { redirect_to(@medium, :notice => 'Medium was successfully created.'); }since is a redirection the code will be a 3XX and you can’t change it or the redirection won’t workFor
format.xml { render :xml => @medium, :status => :created, :location => @medium; }you are declaring the status as created, this means for rails that the code is 201, for making it a 200 change it for:format.xml { render :xml => @medium, :status => :ok, :location => @medium; }