Q:

how to pass params as json in ajax call from ruby?

I am making ajax rest call from ruby and its going to python to do  rest call proccess. when i trying to call rest and passing params in json formate, i think its may not passing this as json data.
My ajax call is following:
get '/cnet' do
    temp="mynet"
    url = URI.parse('http://192.168.1.9:8080/v2.0/networks') 
    params = {'net_name'=>temp}.to_json
    resp = Net::HTTP.post_form(url, params)
    resp_text = resp.body
    puts resp_text    
    erb resp_text
end

Python code is following:
@app.route('/v2.0/networks',methods=['POST'])
def net_create():
    net_res=request.json
    print "======================="
    print net_res['net_name']
    print "======================="
    net_name=net_res['net_name']

when i am trying to read json data from python its giving following error:
File "/network-ui/neutron_plugin.py", line 226, in net_create
    net_name=net_res['net_name']
TypeError: 'NoneType' object has no attribute '__getitem__'

I don't know what is exactly happening.
I am following there link for ajax post call:
http://rest.elkstein.org/2008/02/using-rest-in-ruby.html
http://developer.yahoo.com/ruby/ruby-rest.html
Any help much appreciated. Thanks

A:

Don't pass JSON to Net::HTTP. The method requires a simple ruby hash.
In fact, you send POST params - POST params are sent through the HTTP request body, they are not JSON or whatever, just simple strings. This is HTTP basics, so i suggest you read a bit about how things work over this protocol, it will be a lot easier if you understand it.
Regarding the python side, I don't know much Python but if you really need JSON (which i doubt), you will have to somehow parse the params.

