草庐IT

arguments

全部标签

ruby - Jekyll 服务 "Error: Invalid argument"问题

我目前正在运行在我的Windows7PC上本地安装和生成Jekyll站点的阶段。我已经安装了所有要求并且可以让Jekyll启动,但我无法让它提供服务。每当我尝试时,它都会返回以下错误:$jekyllserve-tConfigurationfile:c:/wamp/www/ShaunYearStrong.github.io/_config.ymlSource:c:/wamp/www/ShaunYearStrong.github.ioDestination:c:/wamp/www/ShaunYearStrong.github.io/_siteGenerating...c:/Ruby193/

ruby - 如何防止将位置参数扩展为关键字参数?

我想要一个接受散列和可选关键字参数的方法。我尝试定义这样的方法:deffoo_of_thing_plus_amount(thing,amount:10)thing[:foo]+amountend当我使用关键字参数调用此方法时,它按预期工作:my_thing={foo:1,bar:2}foo_of_thing_plus_amount(my_thing,amount:20)#=>21然而,当我省略关键字参数时,散列被吃掉了:foo_of_thing_plus_amount(my_thing)#=>ArgumentError:unknownkeywords:foo,bar如何防止这种情况发生

ruby-on-rails - 如何访问 ActiveJob 救援中的执行参数

我想知道您如何访问救援block中的ActiveJob执行参数,例如defperformobjectendrescue_fromExceptiondo|e|ife.class!=ActiveRecord::RecordNotFound**job.arguments.first**#dosomethingendend谢谢!! 最佳答案 在rescue_fromblock中使用arguments是可能的:rescue_from(StandardError)do|exception|user=arguments[0]post=argume

ruby-on-rails - Form_for "First argument in form cannot contain nil or be empty"错误

我不明白为什么会收到此错误,也不知道它的确切含义。Firstargumentinformcannotcontainnilorbeempty(Line3)添加新帖子//ErrorhereController:classPostsController"Yourpostwassaved"elserender"new"endenddefeditenddefupdateenddefdestroyendend 最佳答案 假设您从PostsController渲染它并使用传统的View名称,您的new方法应该创建一个新的Post并分配给它:def

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 - 将命名参数作为 Ruby 中的局部变量

当我为方法使用命名参数时,我发现自己经常在Ruby中编写我认为不必要的代码。以下面的代码为例:defmy_method(args)orange=args[:orange]lemon=args[:lemon]grapefruit=args[:grapefruit]#codethatuses#orange,lemon&grapefruitinthisformatwhichiswayprettier&concisethan#args[:orange]args[:lemon]args[:grapefruit]puts"my_methodvariables:#{orange},#{lemon},

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 - 如何同时使用 splat 和可选哈希在 ruby​​ 中定义方法?

这个问题在这里已经有了答案:Optionalargumentaftersplatargument(6个答案)关闭8年前。我可以这样定义一个方法:deftest(id,*ary,hash_params)#Dostuffhereend但这使得hash_params参数成为强制性的。这些也不起作用:deft(id,*ary,hash_params=nil)#SyntaxError:unexpected'=',expecting')'deft(id,*ary,hash_params={})#SyntaxError:unexpected'=',expecting')'有没有办法让它成为可选的?