Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Can';t获取Curl URL以在Ruby模块方法中工作_Ruby_Curl_Curb - Fatal编程技术网

Can';t获取Curl URL以在Ruby模块方法中工作

Can';t获取Curl URL以在Ruby模块方法中工作,ruby,curl,curb,Ruby,Curl,Curb,我有一个问题,我不能得到以下任何方法,(1,2和3)的工作 require "curb" @username = 'user' @api_key = 'key' @base_uri = 'https://url.com' @offer_id = 999 @login_method = "login=#{@username}&api_key=#{@api_key}" @method_3_url ="#{@base_uri}/3/?#{@login_method}" module My_

我有一个问题,我不能得到以下任何方法,(1,2和3)的工作

require "curb"

@username = 'user'
@api_key = 'key'
@base_uri = 'https://url.com'
@offer_id = 999
@login_method = "login=#{@username}&api_key=#{@api_key}"
@method_3_url ="#{@base_uri}/3/?#{@login_method}"

module My_script
  def self.call_method(url)
    Curl::Easy.http_get(url){|curl| curl.follow_location = true; curl.max_redirects=10;}
  end

  def self.method1
    call_method("#{@base_uri}/1/#{@login_method}")
  end

  def self.method2
    call_method("#{@base_uri}/2/?#{@login_method}")
  end

  def self.method3
    call_method("#{@base_uri}/3/?#{@login_method}")
  end
end
我得到以下错误:

Curl::Err::MalformedURLError:URL使用错误/非法格式或缺少 来自 /Users/home/.rvm/gems/ruby-2.0.0-p598/gems/curb-0.8.8/lib/curl/easy.rb:72:in `表演

当我运行call\u method(@method\u 3\u url)时,它似乎工作正常

我还可以将原始的帖子URL粘贴到Chrome中,这样就可以了


我已经花了几个小时在网上寻找解决方案,但我似乎无法让它发挥作用。。在使用HTTParty时,我也会遇到类似的错误。请帮助:-)

您的实例变量不在模块中,因此超出范围

而不是:

@foo = 'bar'

module Foo
  ...
end
您正在寻找:

module Foo
  @foo = 'bar'
  ...
end