草庐IT

fcatch-undefined-behavior

全部标签

ruby - Nokogiri 错误 : undefined method `radiobutton_with' - Why?

我尝试使用mechanize(Ruby)访问表单。在我的表单上,我有一组单选按钮。所以我想检查其中一个。我写道:target_form=(page/:form).find{|elem|elem['id']=='formid'}target_form.radiobutton_with(:name=>"radiobuttonname")[2].check在这一行中,我想检查值为2的单选按钮。但是在这一行中,我得到一个错误::undefinedmethod`radiobutton_with'for#(NoMethodError) 最佳答案

ruby - rspec 期望抛出 "undefined method"

我是一个完整的Ruby新手,正在玩rspec我正在测试一个包含这一行的类(帐户):attr_reader:balance当我尝试用这种方法测试它时:it"shoulddeposittwice"do@acc.deposit(75)expect{@acc.deposit(50)}.tochange(Account.balance).to(125)end我收到这个错误:NoMethodErrorin'Accountshoulddeposittwice'undefinedmethod`balance'forAccount:Class我不明白为什么我会收到错误,因为存在属性“balance”,但

ruby - 如何在不出现 'undefined method' 错误的情况下访问数组深处的元素

这个问题在这里已经有了答案:RubyStyle:Howtocheckwhetheranestedhashelementexists(16个答案)HowtoavoidNoMethodErrorfornilelementswhenaccessingnestedhashes?[duplicate](4个答案)关闭7年前。当尝试访问数组深处的元素时,如果元素不存在,避免出现错误“undefinedmethod`[]'fornil:NilClass”的最佳方法是什么?例如,我目前正在这样做,但对我来说似乎很糟糕:if@foursquare['response']['groups'][0].pre

Ruby 动态数组 : undefined local variable or method `s' for main:Object (NameError)

我对ruby​​还是个新手。由于某种原因没有看到我的数组。我在irb中测试了我的代码逻辑,它似乎工作正常,但是当我在if语句中使用它时,它因标题中的错误而中断。$s=[]i=0File.open("test.log").eachdo|l|ifl=~/(m.)/s一个例子test.log:aaaaaaaaaaaaaaaaaam1gggp1p2p3p4oooooooooooooom2p1p2p3p4p5ggggggggggggggm3p1kkkkkkkkkkkkm4m5llllllllllllll我怎样才能得到这样的数组?[[m1,p1,p2,p3,p4],[m2,p1,p2,p3,p4,

ruby-on-rails - session 和 rails : Sessions a undefined variable/method?

所以,我有这个错误:ApplicationController:Class的未定义局部变量或方法session所以我猜测是Rails,在设置之前没有“session”变量,对吗?或者我做错了什么。这是使用它的代码:classApplicationController我是在登录页面设置的。是否有一种方法可以只执行它不是零,还是因为它确实未定义而不起作用?我检查session是否正确?设置session的代码:classSessionsController结束所以...知道此错误消息甚至意味着什么。我看到有一个这样的问题,但根据我的测试,那是不一样的(或者是吗?)

ruby - 奇怪的 "undefined method ` absolute_path'”错误

当我尝试这样做时(realcode):fh=File.new("afilename","w")fh_path=File.absolute_path(fh)我得到一个未定义的方法`absolute_path'forFile:Class(NoMethodError)在Ruby文档中说:absolute_path是File的一个方法,所以我不明白这个NoMethodError。我是不是用错了方法? 最佳答案 检查您的Ruby版本。方法absolute_path是addedin1.9.1,似乎。

ruby-on-rails - 升级到 Rails 3.2.2 : How to solve the 'undefined method for Syck::DomainType' error related to the Delayed Job gem?

我正在从3.1.0开始运行RubyonRails3.2.2。我有问题undefinedmethodsend_register_email\'for#\n//.rvm/gems/ruby-1.9.2-p290/gems/delayed_job-3.0.1/lib/delayed/performable_mailer.rb:6:inperform...使用许多其他人尝试解决的DelayedJobgem:有人成功地解决了这个问题,其他人则没有。如果我尝试了我在网上找到的所有解决方案,我属于后一类。此时,在我的Gemfile中我有:gem'rails','3.2.2'gem"rake"...g

ruby - Rails3 : Functional tests fail with NoMethodError: undefined method `user' for nil:NilClass

我将Devise(v2.1.2)与Omniauth一起用于用户验证。我正在对一个Controller进行功能测试,该Controller将JSON对象作为POST主体,因此使用了thisquestion中的技术。设置原始POST正文。这适用于开发,但是当我运行测试时,我在一个完全未经身份验证的方法上遇到异常:NoMethodError:undefinedmethod`user'fornil:NilClass示例测试:test"shouldbeabletocreateanitem"dom=FactoryGirl.attributes_for(:item)raw_post:create,{

ruby-on-rails - 迁移错误 : undefined method `cache' for Gem:Module

通过Rails应用程序迁移时出现此错误undefinedmethod`cache'forGem:Module正在使用Rails3.2.9Ruby1.8.7Ubuntu12.04rakedb:migrate--trace/home/rajendran/.rvm/gems/ruby-1.8.7-p374/gems/extlib-0.9.15/lib/extlib/object.rb:138:warning:methodredefined;discardingoldtry_dup/home/rajendran/.rvm/gems/ruby-1.8.7-p374/gems/extlib-0.9

ruby-on-rails - 无方法错误 : undefined method `mail' for main:Object on rails console

我正在尝试测试邮件程序的工作。通常在Rails上,我首先在控制台级别测试我的代码逻辑,一旦成功,我将其放入真正的源代码中。在ApplicationMailer上工作时,我正在尝试做同样的事情。我遵循了其他一些解决方案,首先在Rails控制台上运行以下命令以首先设置ActionMailerActionMailer::Base.delivery_method=:smtpActionMailer::Base.smtp_settings={address:'smtp.gmail.com',port:587,domain:'gmail.com',authentication:'plain',en