草庐IT

method-removed-here

全部标签

ruby-on-rails - ruby 弃用警告 : You are using the old router DSL which will be removed in Rails 3. 1

我正在使用Rails3,目前正在为我的应用程序编写测试。我收到这个奇怪的弃用警告:DEPRECATIONWARNING:YouareusingtheoldrouterDSLwhichwillberemovedinRails3.1.Pleasecheckhowtoupdateyourroutesfileat:http://www.engineyard.com/blog/2010/the-lowdown-on-routes-in-rails-3/.(calledfromat/Users/jeljer/Dropbox/webCMS/config/environment.rb:6)当然我的路由

ruby-on-rails - RSpec 1.3.3 Rails 2.3.9 Webrat 0.7.3 "undefined method ` 赋值`"

我的规范require'spec_helper'describe'user_sessions/new.html.erb'dolet(:user_session){mock_model(UserSession).as_null_object}beforedoassign(:user_session,user_session)endit'shouldhavethesigninheader'dorenderrendered.shouldcontain('Signin')endendthrow1)NoMethodErrorin'user_sessions/new.html.erbshouldh

Ruby Koans about_methods 第 123 行对象循环

每次我添加正确的代码时,由于每次都更改AboutMethods:0x00000101841a28数字,它会给我同样的错误。就像它卡住了,我不知道如何摆脱这个循环。它工作了一次,然后我继续下一步,但之后它触发了一个错误。我一定没有输入控制台给出的正确代码行?deftest_calling_private_methods_with_an_explicit_receiverexception=assert_raise(NoMethodError)doself.my_private_methodendassert_match"privatemethod`my_private_method'ca

ruby - 猴子修补 : Does define_method take precedence over bind?

在下面的代码片段中,我使用define_methodblock猴子修补Foo#bar。初始化Foo的新实例后,我用bind调用父类bar方法覆盖它,但是当我调用该方法时调用define_methodblock定义的block。为什么bind调用不改变方法的行为?classOriginalFoodefbarputs'inOriginalFoo!'endendclassFoo#OriginalFoo.instance_method(:bar).bind(foo_instance)#=>#foo_instance.bar#>>indefine_methodblock#>>inFoo

ruby - Rails 事件记录 : Calling Build Method Should Not Save To Database Before Calling Save Method

我有一个简单的用户模型classUser还有一个简单的user_profile模型classUserProfile问题是当我调用下面的构建方法时,没有调用保存方法,我最终在数据库中得到了一条新记录(如果它通过了验证)classUserProfilesController任何人都知道发生了什么事。这个方法的定义如下,但它仍然为我保存build_association(attributes={})Returnsanewobjectoftheassociatedtypethathasbeeninstantiatedwithattributesandlinkedtothisobjectthro

ruby-on-rails - 为什么在生产中出现 "undefined method ' paginate'"错误?

在生产服务器上使用will_paginate时出现此错误:I,[2013-10-24T20:17:40.386696#18564]INFO--:StartedGET"/meals"for190.273.432.55at2013-10-2420:17:40+0000I,[2013-10-24T20:17:40.388972#18564]INFO--:ProcessingbyMealsController#indexasHTMLI,[2013-10-24T20:17:40.395022#18564]INFO--:Completed500InternalServerErrorin6msF,[

ruby-on-rails - 方法 `method` 在 `&Unit.method(:new)` 中做了什么?

我是Rails的新手,正在尝试弄清楚我给出的代码。&Unit.method(:new)中的方法method做了什么?&是什么意思?Unit模型中没有方法method并且想知道为什么它可以在那里。最后,我猜:new符号创建了Unit的新对象?classUnitincludeActiveModel::Modelattr_accessor:numberendclassProductincludeActiveModel::Model..................defunits=(values)@units=values.map(&Unit.method(:new))endend

ruby - Watir 消息 : Instead of passing arguments into #wait_until_present method, 使用关键字

我在填写表格后使用watir和firefox抓取网页。这是我的代码的一小部分:browser.button(:type=>'submit').clicksleep10browser.element(:id=>'footer').wait_until_present(timeout=30)html=browser.html出现此消息:Insteadofpassingargumentsinto#wait_until_presentmethod,useKeywords这是什么意思?我该如何解决这个问题?感谢您的帮助。 最佳答案 答案在新的

ruby - 为什么在 Ruby 中捕获命名组会导致 "undefined local variable or method"错误?

我在Ruby2.0的正则表达式中遇到命名捕获问题。我有一个字符串变量和一个内插正则表达式:str="helloworld"re=/\w+//(?#{re})/=~strgreeting它引发了以下异常:prova.rb:4:in':undefinedlocalvariableormethodgreeting'formain:Object(NameError)shellreturned1但是,内插表达式在没有命名捕获的情况下也能工作。例如:/(#{re})/=~str$1#=>"hello" 最佳答案 命名捕获必须使用文字您遇到了Ru

Ruby 元编程 : How can make module method see class's variable

例如我有一个模块和一个类:moduleSimpleModuledefself.class_helloputs"hellofrom#{@@name}"endendclassSimpleClass@@name='StackOverFlow'defself.testSimpleModule.class_helloendend然后我通过从类中调用模块方法进行测试:SimpleClass.test我遇到异常:uninitializedclassvariable@@nameinSimpleModule(NameError)我知道这里是因为模块范围与类范围不同。所以我的问题是:如何为SimpleMo