respond_with with templates and http status when creating an object


When you use respond_with in a controller #create method and want to render XML the response gets the http status 201 (Created).

But if you use a view to render this XML response_with uses the status 200 (Ok), for example when you use the gem rabl.

I cannot determine if this matter is related to Rails or rabl. If it’s from Rails, is there a particular reason for this behavior?

I was able to perform what I’m talking about in an initializer, maybe it can help seeing the big picture:

ActionController::Responder.class_eval do

def to_format

if has_errors?

api_behavior(nil) and return


controller.response.status = :created if post? && ! has_errors?


rescue ActionView::MissingTemplate => e




Now I understand a lot better Rails view stack.

As for my problem, the culprit is this line in mime_responds.rb:

collector = { default_render }

which calls the default view without options (I guess this is a functionality and not a bug since it’s name is “default_render”).

Hmm anyone?