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: curl ''http://www.whatsayye.com/questions.json?callback=jsonp12345'' \ -X "POST" \ -H "Content-Type: application/json" \ -H "Accept: application/json" \ -d "{ \"question\": { \"question\": \"Created with curl JSON-ically\", \"url\": \"curljson\" }}" curl ''http://www.whatsayye.com/questions/3.json'' \ -X "PUT" \ -H "Content-Type: application/json" \ -H "Accept: application/json" \ -d "{ \"question\": { \"question\": \"Modified with curl JSON-ically\", \"url\": \"jsonrocks\" }}" Failing Examples: curl ''http://www.whatsayye.com/questions/3.json'' \ * -X "POST" \* -H "Content-Type: application/json" \ -H "Accept: application/json" \ * -d "_method=put" \* -d "{ \"question\": { \"question\": \"Modified with curl JSON-ically\", \"url\": \"jsonWAYrocks\" }}" -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
_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 On Sat, Nov 28, 2009 at 9:05 AM, AJ ONeal <Alvin.ONeal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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: > curl ''http://www.whatsayye.com/questions.json?callback=jsonp12345'' \ > -X "POST" \ > -H "Content-Type: application/json" \ > -H "Accept: application/json" \ > -d "{ \"question\": { \"question\": \"Created with curl > JSON-ically\", \"url\": \"curljson\" }}" > > curl ''http://www.whatsayye.com/questions/3.json'' \ > -X "PUT" \ > -H "Content-Type: application/json" \ > -H "Accept: application/json" \ > -d "{ \"question\": { \"question\": \"Modified with curl > JSON-ically\", \"url\": \"jsonrocks\" }}" > > Failing Examples: > curl ''http://www.whatsayye.com/questions/3.json'' \ > * -X "POST" \* > -H "Content-Type: application/json" \ > -H "Accept: application/json" \ > * -d "_method=put" \* > -d "{ \"question\": { \"question\": \"Modified with curl > JSON-ically\", \"url\": \"jsonWAYrocks\" }}" > > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
> _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 -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 > 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-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.