TypeError - no implicit conversion of nil into String Sinatra

落爺英雄遲暮 提交于 2019-12-12 16:28:18

问题


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

来源:https://stackoverflow.com/questions/40038922/typeerror-no-implicit-conversion-of-nil-into-string-sinatra

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!