class MenuController < ApplicationController
        respond_to :json

        def show
                @items = {:foo => 'bar'}
                respond_with(@items)
        end

end

Request GET /menu/1.json HTTP/1.1

Response

HTTP/1.1 200 OK
X-Ua-Compatible: IE=Edge
Etag: "37a6259cc0c1dae299a7866489dff0bd"
Connection: close
Content-Type: application/json; charset=utf-8
Date: Tue, 04 Oct 2011 18:13:07 GMT
Server: WEBrick/1.3.1 (Ruby/1.8.7/2010-04-19)
X-Runtime: 0.381781
Content-Length: 4
Cache-Control: max-age=0, private, must-revalidate

null

As you see, I get 'null' back. But manually setting the status in
respond_with seems to work!


class MenuController < ApplicationController
        respond_to :json

        def show
                @items = {:foo => 'bar'}
                respond_with(@items, :status => 200)
        end

end

Request GET /menu/1.json HTTP/1.1

Response

HTTP/1.1 200 OK
X-Ua-Compatible: IE=Edge
Etag: "9bb58f26192e4ba00f01e2e7b136bbd8"
Connection: close
Content-Type: application/json; charset=utf-8
Date: Tue, 04 Oct 2011 18:15:03 GMT
Server: WEBrick/1.3.1 (Ruby/1.8.7/2010-04-19)
X-Runtime: 0.232898
Content-Length: 13
Cache-Control: max-age=0, private, must-revalidate

{"foo":"bar"}


What gives?

-- 
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby

Reply via email to