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
end
controller.response.status = :created if post? && ! has_errors?
default_render
rescue ActionView::MissingTemplate => e
api_behavior(e)
end
end
Now I understand a lot better Rails view stack.
As for my problem, the culprit is this line in mime_responds.rb:
collector = Collector.new { 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”).
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.