On Mar 4, 2011, at 1:35 AM, Michael Koziarski wrote:

class CommentsController < ApplicationController
 respond_to :html, :xml
 def new
   @comment = Comment.new
   respond_with(@comment, :status => :created)
 end
end

It's off topic, but this is a curious response code to send for new.
You haven't created anything at all ;)

Obviously, this isn't my actual code, it was just the shortest working example I could think of. Maybe :created was a bad example. Pretend I said :partial_content, or one of the other 50 status codes ;-)


For html requests, the response code will be the standard :ok 200
code. But for xml request, or json, or any other acceptable request
mime type, the :created status will be returned.

This kind of thing is to be expected because sending the 'right'
response code to a browser doesn't lead to the correct behaviour from
a user's perspective.  For example an API's create action sends a 201
response, however browsers want a 302 redirect.  You can see this kind
of thing here:

https://github.com/rails/rails/blob/master/actionpack/lib/action_controller/metal/responder.rb #L142-167

Not necessarily. My specific use-case is with sending an AJAX request (via the jquery-ujs) for an HTML snippet. The jQuery callbacks look at the response code, and so it is useful to have control over them without needing to resort to respond_to or format.html{ ... }.

Also, it's not just :status, I can't override :layout either. This doesn't work for html requests either:

respond_with(@comment, :layout => :false)


So, should I add the test case and submit the patch, or should I
update the documentation to be clear that it doesn't work for html
requests? Oh also, it's not specific to just :status, it also doesn't
work for several other options.

I believe it's deliberate here, but if you can track down some errant
looking code, do raise a ticket with a patch.

If it's a bug, I have no problem writing the tests, fixing it, and submitting the patch. I just wanted to make sure there's not some obvious reason I'm missing that this behavior would be intended.



On a related note, I tried using the #display method like in the
excerpted comments, but I get a wrong number of arguments error (2 for
0..1).

Thanks everyone!

-Steve Schwartz
@jangosteve

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to [email protected] . To unsubscribe from this group, send email to [email protected] . For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en .





--
Cheers

Koz

--
You received this message because you are subscribed to the Google Groups "Ruby on 
Rails: Core" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.

Reply via email to