# Respond\_with with templates and http status when creating an object

**URL:** <https://www.ruby-forum.com/t/respond-with-with-templates-and-http-status-when-creating-an-object/210716>\
**Category:** Rails\
**Created:** [August 15, 2011, 6:23pm UTC](https://www.ruby-forum.com/t/respond-with-with-templates-and-http-status-when-creating-an-object/210716 "2011-08-15T18:23:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [August 15, 2011, 6:23pm UTC](https://www.ruby-forum.com/t/respond-with-with-templates-and-http-status-when-creating-an-object/210716/1 "2011-08-15T18:23:25Z")

</div>

Hi.

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?

---

<div class="post-metadata">

**Author:** ![dagnan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/49beb7/32.png) [@dagnan](https://www.ruby-forum.com/u/dagnan)\
**Post date:** [August 17, 2011, 11:33am UTC](https://www.ruby-forum.com/t/respond-with-with-templates-and-http-status-when-creating-an-object/210716/2 "2011-08-17T11:33:10Z")

</div>

Hmm anyone?

---

<div class="post-metadata">

**Author:** ![dagnan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/49beb7/32.png) [@dagnan](https://www.ruby-forum.com/u/dagnan)\
**Post date:** [August 15, 2011, 10:21pm UTC](https://www.ruby-forum.com/t/respond-with-with-templates-and-http-status-when-creating-an-object/210716/3 "2011-08-15T22:21:18Z")

</div>

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

```ruby
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:

```auto
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”).
