Hi all, I'm wondering if this is a bug, or if I'm misunderstanding the
code. I'm looking at the ActionController respond_with method, and
noticed that any options passed through don't work for format.html.
For example:

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

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.

The comments in actioncontroller/metal/responder.rb would lead me to
believe that this should work.

    # Display is just a shortcut to render a resource with the current
format.
    #
    #   display @user, :status => :ok
    #
    # For XML requests it's equivalent to:
    #
    #   render :xml => @user, :status => :ok
    #
    # Options sent by the user are also used:
    #
    #   respond_with(@user, :status => :created)
    #   display(@user, :status => :ok)
    #
    # Results in:
    #
    #   render :xml => @user, :status => :created

I also was curious how this could possibly get through as a bug, so I
checked the test suite and it looks like it's tested specifically with
a non-html request, which explains why the test would pass. But I'm
not sure why anyone would go out of their way to make the test
specifically request a non-standard mime-type unless it's intentional
behavior. From test/controller/mime_responds_test.rb:

  def test_using_resource_with_status_and_location
    @request.accept = "text/html"
    post :using_resource_with_status_and_location
    assert @response.redirect?
    assert_equal "http://test.host/";, @response.location

    @request.accept = "application/xml"
    get :using_resource_with_status_and_location
    assert_equal 201, @response.status
  end

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.

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.

Reply via email to