Ruby dashingio和rest客户端出现Sinatra错误

Ruby dashingio和rest客户端出现Sinatra错误,ruby,gem,sinatra,rest-client,dashing,Ruby,Gem,Sinatra,Rest Client,Dashing,我正在dashingio作业中使用rest客户端。自从为rest客户机添加代码以来,我在破折号开始时出现以下错误 Gemfile source 'https://rubygems.org' gem 'dashing' ## Remove this if you don't need a twitter widget. gem 'twitter', '>= 5.9.0' myjob.rb require "rubygems" require "json" require "

我正在dashingio作业中使用rest客户端。自从为rest客户机添加代码以来,我在破折号开始时出现以下错误

Gemfile

source 'https://rubygems.org'

gem 'dashing'

## Remove this if you don't need a twitter widget.
gem 'twitter', '>= 5.9.0'
myjob.rb

  require "rubygems"
  require "json"
  require "rest-client"
  require "requests"
  require "pp"
...
  def post(theJson)
    theUrl = $location + $endpoint.to_str
    begin
        response = RestClient.post(theUrl, theJson, :content_type => :json)
        if(response.code > 204)
            $stderr.puts("Failed to post Json to endpoint " + theUrl + "\nReturn code: " + response.code.to_s)
            exit 1
        end
    rescue Errno::ECONNREFUSED
        $stderr.puts("Server refusing connection!")
        exit 1
    end
    if(JSON.parse(response).has_key?("error")) then
        $stderr.puts("Returned an error...")
        $stderr.puts JSON.parse(response)["error"]
        exit 1
    end
    return(response)
  end

我怀疑这可能是因为您将自己的方法命名为post,这与Sinatra自己的post方法相冲突。错误似乎来自Sinatra的post导致的代码路径。您可能需要将方法名称更改为其他名称。@matt就是这样,谢谢:
  require "rubygems"
  require "json"
  require "rest-client"
  require "requests"
  require "pp"
...
  def post(theJson)
    theUrl = $location + $endpoint.to_str
    begin
        response = RestClient.post(theUrl, theJson, :content_type => :json)
        if(response.code > 204)
            $stderr.puts("Failed to post Json to endpoint " + theUrl + "\nReturn code: " + response.code.to_s)
            exit 1
        end
    rescue Errno::ECONNREFUSED
        $stderr.puts("Server refusing connection!")
        exit 1
    end
    if(JSON.parse(response).has_key?("error")) then
        $stderr.puts("Returned an error...")
        $stderr.puts JSON.parse(response)["error"]
        exit 1
    end
    return(response)
  end