草庐IT

start_requests

全部标签

ruby - 加载网页时 : "undefined method ` request_uri' for #"

我正在尝试使用Ruby通过HTTP加载网页并检查其状态代码是什么。我的代码如下所示:require"net/http"@r=Net::HTTP.get_response(URI.parse(myURL))return@r.code但是,对于某些URL(主要是指向奇怪的东西,例如不会给出正确响应的Web计数器),我得到了一个undefinedmethodrequest_urifor#异常。我已经将它追溯到http.rb的第380行(我正在运行Ruby1.8),它说:defHTTP.get_response(uri_or_host,path=nil,port=nil,&block)ifpa

ruby-on-rails - RubyMine Debugger.start 尚未调用

我在使用RubyMine调试时遇到了这个异常...Debugger.startisnotcalledyet. 最佳答案 在尝试其他建议的解决方案一段时间后,我发现我在gem文件中有以下内容:gem"debugger"这会以某种方式导致调试器发生冲突...删除这一行对我来说解决了...谢谢...来源:Debuggercrasheswhenithitsthefirstbreakpoint 关于ruby-on-rails-RubyMineDebugger.start尚未调用,我们在StackO

ruby-on-rails - 我如何在 Rails 的模型中获取 request.uri?

$request=request当我在Controller中编写它时,它会起作用。但是,如果我在模型或应用程序Controller中需要这个变量,我该怎么办? 最佳答案 模型存在于网络请求的上下文之外。您可以在irb中实例化它们,您可以在延迟作业或脚本中实例化它们,等等。如果模型依赖于请求对象,那么这些事情都不可能发生。正如tsdbrown所说,您必须以某种方式从使用模型的上下文中传递该信息。 关于ruby-on-rails-我如何在Rails的模型中获取request.uri?,我们在

ruby-on-rails - rails : Plus sign in GET-Request replaced by space

在Rails3(Ruby1.9.2)中我发送一个请求StartedGET"/controller/action?path=/41_+"但是参数列表是这样的:{"path"=>"/41_","controller"=>"controller","action"=>"action"}这里出了什么问题?-、*或.符号工作正常,只是+将被空格替换。 最佳答案 这是正常的URL编码,theplussignisashorthandforaspace:Withinthequerystring,theplussignisreservedasshor

ruby-on-rails - 在 Rails 4 中接收 POST 数据并读取 request.body

我想向Rails应用程序发送POST请求,并让它在数据库中保存和解析请求主体...我在接收端的路线目前设置为:post'/request'=>'controller#receives_data'当我将数据发布到我使用的这个Controller时:defpost_itconnection.post(uri.path,"thisisdata",header_with_authkey)end我接收帖子的Controller方法设置为:defreceives_datalog(request.body.read)end但是我得到了一个422错误,无法处理的实体,并且日志文件总是空的...是否需要

关于Document mapping type name can‘t start with ‘_‘, found: [_update]

在修改elasticsearch时,用_update进行局部修改,修改失败,报错{    "error": {        "root_cause": [            {                "type": "invalid_type_name_exception",                "reason": "Document mapping type name can't start with '_', found: [_update]"            }        ],        "type": "invalid_type_name_exce

ruby-on-rails - 我如何在我的 RSpec 中设置 request.referrer?

我试图避免使用我的session[:referred_by],而想使用request.referrer。但是,我的RSpec测试失败了,因为TestRequest没有存储request.referrer因此,为了使Rspec测试正常工作,我必须执行以下操作。有没有办法让它变得更好:referrer=request.referrer?request.referrer:'/'redirect_toreferrer,:alert=>error_message 最佳答案 ActionDispatch::TestRequest扩展了Actio

ruby - 如何在当前类的上下文中运行 IRB.start

我刚看完PragProgContinuousTestingWithRuby,他们讨论了在当前类的上下文中调用IRB以手动检查代码。但是,他们引用说,如果您在类中调用IRB.start,self是预定义的,并且指的是调用start时我们所在的对象这对我来说不是真的。即使是非常简单的例子a="hello"require'irb'ARGV.clear#otherwiseallscriptparametersgetpassedtoIRBIRB.start当我尝试访问a变量时,我得到了明显的结果NameError:undefinedlocalvariableormethod`a'formain:

ruby-on-rails - 我得到 "found character that cannot start any token while scanning for the next token"

我已经在我的笔记本电脑上运行RubyonRails大约一个月了,但是当我想在这个实例中运行服务器时(它在几个小时前工作正常)我现在收到这条消息。请问如何让服务器再次运行?C:\Sites\LaunchPage>railssC:/RailsInstaller/Ruby1.9.3/lib/ruby/1.9.1/psych.rb:203:in`parse':():foundcharacterthatcannotstartanytokenwhilescanningforthenexttokenatline17column17(Psych::SyntaxError)fromC:/RailsIns

ruby - 如何在 OpenURI 中指定 "http request header"

我正在尝试使用Ruby的OpenURIgem调用URL,但是它需要我在其HTTP请求header中传递某些值。知道怎么做吗? 最佳答案 根据thedocumentation,您可以将httpheader的哈希值作为第二个参数传递给open:open("http://www.ruby-lang.org/en/","User-Agent"=>"Ruby/#{RUBY_VERSION}","From"=>"foo@bar.invalid","Referer"=>"http://www.ruby-lang.org/"){|f|#...}