草庐IT

argument2

全部标签

ruby-on-rails - 参数错误 : wrong number of arguments (1 for 2)

我是Rails、MVC和CRUD的新手,我正在尝试使用更新方法来更改帖子的投票数量。我的PostsController更新方法中有以下代码:defupdate@post=Post.find(params[:id])ifparams[:vote]=='up'@post.update_column(:ups=>@post[:ups]+1)elsifparams[:vote]=='down'@post.update_column(:downs=>@post[:downs]+1)endflash[:notice]="Thanksforvoting!Thishelpsusdetermineimp

ruby - 获取 `initialize' : wrong number of arguments(1 for 0) (ArgumentError) for simple ruby app

这是我的第一个ruby应用程序。我是一个堆栈溢出处女......当我运行以下程序时:classNameAppdefintialize(name)@names=[]enddefname_questionprint"Whatisyourname?"answer=gets.chomp@names+=answer.to_sputs"Thenumberofcharactersinyournameis"+names.lengthenddefname_lengthif@names.length>25thenprint"Yournameislongerthan25characters."elsepri

ruby-on-rails - minitest_plugin.rb :9 getting wrong number of arguments

~/Sites/sample_app$railstestRunningviaSpringpreloaderinprocess24338Runoptions:--seed58780Running:..Finishedin0.292172s,6.8453runs/s,6.8453assertions/s./var/lib/gems/2.3.0/gems/railties-5.1.0/lib/rails/test_unit/minitest_plugin.rb:9:in`aggregated_results':wrongnumberofarguments(given1,expected0)(

ruby - 如何解决 factory_girl wrong number of arguments 错误

#rspectestcode@room=FactoryGirl.build(:room)#factorydefinitionfactory:roomdolength{10}width{20}end#codeimplementationclassRoomattr_accessor:length,:widthdefinitialize(length,width)@length=length@width=widthendend在尝试构建@room时运行rspec会导致此错误ArgumentError:wrongnumberofarguments(0for2) 最佳

ruby - 如果我不指定 <programfile>,我如何将 <arguments> 传递给 IRB?

自:irb--help用法:irb.rb[选项][程序文件][参数]我知道如果我包含一个程序文件,我可以将参数传递给ARGV例如:irbtest.rbABC其中test.irb只是“pARGV”产生:["a","b","c"]使programfile在DOS中成为con...我可以执行以下操作irbconABCcon(main):001:0>ARGV产生:ARGV=>["A","B","C"]但这是系统相关的并且有回显输入的副作用:-(我真正喜欢的是类似的东西irb--abc顺便说一句:我知道我可以在irb中设置ARGV,但我的意图是别名special==irb-rSpecialLib

ruby - 使用 ( :send) in Ruby with keyword arguments?

我有一个私有(private)方法,我正尝试在Ruby中使用#sendto进行一些测试。该方法很复杂,我不想暴露在类之外,所以我想测试该方法,但我也不需要将其列为公共(public)方法。它有关键字参数。我怎样才能使用send来调用该方法,同时还向它传递关键字参数/命名参数?有办法吗?方法如下所示:defsome_method(keyword_arg1:,keyword_arg2:,keyword_arg3:nil) 最佳答案 取决于关键字参数的定义方式。如果出于某种原因将它们定义为内联,则将它们内联传递:SomeClass.sen

ruby - Rspec 模拟错误 : wrong number of arguments

我正在尝试使用Rspec对StripeAPI进行stub,但我遇到了一个问题。这是我的代码的样子:Stripe::Customer.should_receive(:create).with(any_args).and_raise(Stripe::CardError)这是我遇到的错误:Failure/Error:Stripe::Customer.should_receive(:create).with(any_args).and_raise(Stripe::CardError)ArgumentError:wrongnumberofarguments(0for3..6)

ruby-on-rails - 什么是 "circular argument reference"错误,有 activesupport time_zone?

我是ruby​​onrails的新手,我正在尝试创建一个教程。我在执行rakedb:migrate时遇到问题。hugo@ubuntu:~/pin_board$rakedb:migrate/home/hugo/.rvm/gems/ruby-2.2.2/gems/activesupport-4.0.5/lib/active_support/values/time_zone.rb:283:warning:circularargumentreference-now这是什么原因造成的?有人可以帮我吗? 最佳答案 您看到此警告消息是因为您的Ra

arrays - 如何通过 & :key as an argument to map instead of a block with ruby?

我写了这段代码:my.objects.map{|object|object.key}我的rubocop说:Pass&:keyasanargumenttomapinsteadofablock.有没有捷径可以做同样的事情? 最佳答案 Pass&:keyasanargumenttomapinsteadofablock意思是:my.objects.map(&:key) 关于arrays-如何通过&:keyasanargumenttomapinsteadofablockwithruby?,我们在S

ruby - 定义方法 : How to dynamically create methods with arguments

我想为find_by功能创建一堆方法。我不想一遍又一遍地写同样的东西,所以我想使用元编程。假设我想创建一个按名称查找的方法,接受名称作为参数。我该怎么做?我过去曾使用过define_method,但我没有为该方法采用的任何参数。这是我的(坏的)方法["name","brand"].eachdo|attribute|define_method("self.find_by_#{attribute}")do|attr_|all.eachdo|prod|returnprodifprod.attr_==attr_endendend有什么想法吗?提前致谢。 最佳答案