I am receiving an HTTP POST from a 3rd party with content-type as 'application/x-www-form-urlencoded' in my RAILS 3.0.6 controller
I tried parsing the request both as -
job_status = params['job']['status']
as well as
recd_json = JSON.parse(params) job_status = recd_json['job']['status']
But in both cases the rails controller is throwing the error 'NoMethodError (You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base.'
I am not sure how else can JSON (encoded using this content type) can be parsed..Any help is appreciated :)
Heres the json being posted: { "name": "JSON Parser", "url": "job/test/", "job": { "status": "SUCCESS", "url": "job/356/" } }
Heres the params as returned by the RAILS controller using the Rails.Logger:
{"{ \"name\": \"JSON Parser\", \"url\": \"job/test/\", \"job\": { \"status\": \"SUCCESS\", \"url\": \"job/356/\" }}"=>nil, "action"=>"receive_jobs_updates", "controller"=>"jobs"}
The Error trace:
NoMethodError (You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.[]): app/controllers/jobs_controller.rb:32:in `receive_jobs_updates'
The controller code: def receive_job_updates
Rails.logger.info params
job_name = params['name'] job_status = params['job']['status']
render :text=> "All ok" , :status => :ok
end