Michel Pigassou
2011-Aug-15 16:21 UTC
respond_with with templates and http status when creating an object
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? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/m7TcC8tKKdAJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Michel Pigassou
2011-Aug-15 20:19 UTC
Re: respond_with with templates and http status when creating an object
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:
```
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").
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-talk/-/WvSMC1eYr2IJ.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Michel Pigassou
2011-Aug-17 09:31 UTC
Re: respond_with with templates and http status when creating an object
Hmm anyone? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/J-GXrTJol8wJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.