I can't PUT or DELETE JSON, where do I look?

6 views
Skip to first unread message

AJ ONeal

unread,
Nov 28, 2009, 2:05:04 AM11/28/09
to rubyonra...@googlegroups.com
I'm making a webservice with JSON going in both directions for all requests, but seem to have run into a catch 22.

A) I try the request as "/questions/1.json?_method=put" but since the _method=put is not in the message body it doesn't count.

B) I send the params as _method=put&{ "json": "here" }
The request is recognize as a PUT, but the JSON can't be interpreted.

C) I send the params as { "_method":"put", "json": "here" }
The request isn't recognized as a PUT, but the JSON can be parsed (it works using "curl -X PUT ...")

D) I try using GET (with the same approach as A) and it ignores the parameters and the message body.

Where should I attack this beast at?


AJ ONeal

Working Examples:
        -X "POST" \
        -H "Content-Type: application/json" \
        -H "Accept: application/json" \
        -d "{ \"question\": { \"question\": \"Created with curl JSON-ically\", \"url\": \"curljson\" }}" 

        -X "PUT" \
        -H "Content-Type: application/json" \
        -H "Accept: application/json" \
        -d "{ \"question\": { \"question\": \"Modified with curl JSON-ically\", \"url\": \"jsonrocks\" }}"

Failing Examples:
        -X "POST" \
        -H "Content-Type: application/json" \
        -H "Accept: application/json" \
        -d "_method=put" \
        -d "{ \"question\": { \"question\": \"Modified with curl JSON-ically\", \"url\": \"jsonWAYrocks\" }}"

Johan De Klerk

unread,
Nov 28, 2009, 2:21:26 AM11/28/09
to rubyonra...@googlegroups.com
_method=put&{ "json": "here" } will never work.

In a query string you need to assign it to  something:

eg.
_method=put&json={ "json": "here" }


Johan

--

You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

CoolAJ86

unread,
Nov 28, 2009, 3:00:38 AM11/28/09
to Ruby on Rails: Talk
> _method=put&{ "json": "here" } will never work.
>
> In a query string you need to assign it to  something:
>
> eg. _method=put&json={ "json": "here" }

That won't every work either.
In params_parser.rb the request is treated as wholly JSON, wholly XML,
wholly YAML, or wholly whatever.

If it's JSON it doesn't look for params, it just shoves the parsed
lump sum into a param called :_json
I suppose I could patch that to handle this case, but I'm not sure at
what level I should be looking.

But I'm not clear on the flow of the application. At what level is it
deciding on what is an allowed request? and what is the symbol it
expects? :_method => :WHAT???

I tried :_method => 'put' and :_method => :put. Neither worked

joost

unread,
Dec 19, 2009, 12:11:01 PM12/19/09
to Ruby on Rails: Talk
You are running into this because of a bug/misfeature. See this
lighthouse ticket:
https://rails.lighthouseapp.com/projects/8994/tickets/2289-_methodput-ignored-for-xhr-and-xml-requests

Apparently you can set an HTTP_X_HTTP_METHOD_OVERRIDE header, but that
doesn't work for me either.

On Nov 28, 9:00 am, CoolAJ86 <coola...@gmail.com> wrote:
> > _method=put&{ "json": "here" } will never work.
>
> > In a query string you need to assign it to  something:
>
> > eg. _method=put&json={ "json": "here" }
>
> That won't every work either.

> In params_parser.rb the request is treated as whollyJSON, wholly XML,


> wholly YAML, or wholly whatever.
>

> If it'sJSONit doesn't look for params, it just shoves the parsed

Reply all
Reply to author
Forward
0 new messages