vendredi 14 octobre 2016

TypeError - no implicit conversion of nil into String Sinatra

My code looks like this.. It is to upload the json data into a db after extracting the fields into a hash. But i get 'TypeError - no implicit conversion of nil into String' in line JSON.parse(json_data) of log_extractor.rb

upload_results.erb:

             $( "form" ).submit(function( event ){
                var fileoutput = reader.result;
             //$("#upload_button").click(function(){
             $.ajax({
                      url:'/file_upload',
                      type : "POST",
                      data:  {
                      fileoutputid: fileoutput
                      },
                      dataType: 'json',
                      success: function(response)
                          {
                          },
                      failure: function(response){
                      }
            });
    });

server.rb

              post '/file_upload' do
              file_data = params[:fileoutputid]
              @uploaderobj.fileUpload(file_data)
              end

log_extractor.rb

            @data_hash = JSON.parse(json_data)
            @data_hash['test_results'].keys.length
            end

Aucun commentaire:

Enregistrer un commentaire