I replied to this earlier but I think I may have accidentally clicked
discard instead of send. Sorry if this is a duplicate:
I tried that method (using respond_with). Even then the requests gets
processed as HTML.
So on my Rails 2 setup just setting CONTENT_TYPE = ‘application/json’
causes the request to be processed as a json format.
On Rails 3 that isn’t working so everything gets set as HTML. Do I
need to set HTTP_ACCEPT instead of CONTENT_TYPE? I get the feeling
Rails 3 uses CONTENT_TYPE for the incoming parsing (since the incoming
json is parsed correctly) and I need to set some other type to force a
JSON response. It isn’t clear where that should be set though.
need to set HTTP_ACCEPT instead of CONTENT_TYPE? I get the feeling
Rails 3 uses CONTENT_TYPE for the incoming parsing (since the incoming
json is parsed correctly) and I need to set some other type to force a
JSON response. It isn’t clear where that should be set though.
Can you verify that the following headers are present, the accept
header might actually be what you’re missing out on:
I will try to set HTTP_ACCEPT when I get home. I know it’s not
being set now, but I wasn’t sure if it was required or not.
Something must have changed from 2.3.4 to 3 or I set some
configuration in 2.3.4 that I dont remember…
Well, the Accept header is what tells the server what response you
accept, while the Content-Type header tells the server what type of
data the posted data is, as you can read at http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
Rails 2 might have been more forgiving or you might have just
appended .json to the url, but Rails 3 has the correct behaviour.
Best regards
Peter De Berdt
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.