草庐IT

In-source

全部标签

ruby-on-rails - rails 教程 : Putting flash messages in partial yields error "undefined method ` each' for nil:NilClass"?

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:FlashMessagesinPartials(Rails3)我正在做MichaelHartl的Railstutorial和listing7.26将flash消息添加到应用程序布局:...">...这很好用。但是,我试图通过在我的部分文件夹中创建一个_flash.html.erb来清理这段代码...">-->...并且比使用......在我的应用程序布局中,我的所有Rspec测试开始失败,每个测试都显示以下消息:Failure/Error:before{visitsignup_path}ActionView:

ruby-on-rails - Rails 5 升级 :/actionpack-5. 0.0/lib/action_controller/test_case.rb:49:in `initialize':参数数量错误(0 代表 2)(ArgumentError)

我最近正在进行Rails5升级,当我尝试启动Rails控制台时遇到了这个错误:/actionpack-5.0.0/lib/action_controller/test_case.rb:49:ininitialize':wrongnumberofarguments(0for2)(ArgumentError)当前bundleupdaterails已经完成了gem依赖项的解决,足以更新到5.0.0,rspec正在运行(尽管我正在修复很多中断)。我也可以运行railss没有错误。这里是代码中断行:https://github.com/rails/rails/blob/master/action

ruby-on-rails - Rails 查询 : Filter by properties in another table

我正在寻找一个清晰的Rails4示例,说明如何根据通过另一个表关联的数据过滤记录。假设我有一个用户模型和一个评论模型。一个用户has_many评论,一个Commentbelongs_to一个用户。评论在其表中也有一个score列。classUserUsers|id|name|email||-----|---------|---------------------||1|"Alice"|"alice@example.com"||2|"Bob"|"bob@example.com"||...|classComment我如何获得所有对内容“k”发表评论且分数>0的用户?请注意,我要返回的是用户

ruby :关键字 "in"是什么意思

当我第一次在ruby​​中找到关键字“in”时。我想也许我可以这样做:1英寸(0..10)但看起来我不能那样使用它。然后我在ruby​​-lang.org中搜索它,然后用谷歌搜索它。没有答案!ruby中关键字“in”的含义是什么? 最佳答案 您应该能够执行以下操作:foriin0..10doputsiend您提到的表达式1in(0..10)将不起作用,因为常量(1)不能在一定范围内变化-它是一个常量!您需要在in关键字之前命名一个变量。希望对您有所帮助。参见thispage 关于ruby

ruby - 为什么 inspect for the subclasses of built-in classes 中没有列出实例变量?

当我对内置类进行子类化时,为什么inspect中的行为会发生变化。但是当我子类化一个自定义的时没有看到。classMainErrorendclassAnotherTestErrort=TestError.newputst.inspect#output:# 最佳答案 因为很多(大多数?全部?)内置类是用C语言编写的,并且覆盖#inspect。例如,Exception(StandardError的父类(superclass))定义#inspect如下:exc_inspect(VALUEexc){VALUEstr,klass;klass=

ruby-on-rails - 目录 : Forgot Password & Sign In - in same page

我正在尝试将忘记密码字段与登录页面放在一起,但如果用户未注册(并且不在应用程序数据库中),则它会重定向到原始设计的忘记密码页面并出现错误(http://localhost:3000/用户/密码)。如何使错误出现在与登录页面(http://localhost:3000/users/sign_in)相同的页面中?在app/views/devise/sessions/new.html.erb文件中ForgotPasswordEntertheemailyousignedupwith所以有一个javascript链接,如果用户忘记了他们的登录凭据,输入字段将显示在该链接上。

ruby - MiniTest 的 assert_in_delta 和 assert_in_epsilon 方法有什么区别?

这里是documentationforassert_in_delta:assert_in_delta(exp,act,delta=0.001,msg=nil)publicForcomparingFloats.Failsunlessexpandactarewithindeltaofeachother.assert_in_deltaMath::PI,(22.0/7.0),0.01这里是documentationforassert_in_epsilonassert_in_epsilon(a,b,epsilon=0.001,msg=nil)publicForcomparingFloats.Fa

ruby - 名称错误 : undefined - have parsing rules for local variables changed in Ruby 2. 1.2?

我得到NameError:undefinedlocalvariableormethodwithruby​​2.1.2正如在thisquestion中观察到的那样,表达式如:barifbar=true引发未定义的局部变量错误(前提是bar之前未定义),因为bar在分配之前被解析器读取。而且我相信以前用这个表达式没有什么区别:barifbar=false两者之间的区别在于主体是否被求值,但如果遇到未定义的局部变量会在求值条件之前立即引发错误,那应该无关紧要。但是当我在Ruby2.1.2上运行第二个代码时,它没有引发错误。以前也是这样吗?如果是这样,那么解析讨论的内容是什么?如果没有,Rub

ruby - 如何修复此错误 : kernel_require. rb :45:in `require' : cannot load such file?

我有以下文件结构:执行.rb图书馆我的类(class).rb在execute.rb我有下面的代码:#!/usr/bin/rubyrequire'lib/my_class'my_object=MyClass.newmy_object.some_method这是my_class.rb的代码:classMyClassdefsome_methodputs'OK'endend所以,我尝试运行execute.rb:rubyexecute.rb但是我收到这个错误:/home/vagrant/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/site_ruby/2.0.0/ru

ruby-on-rails - Aws::S3::Presigner undefined method credentials for nil:NilClass in Ruby

我使用了aws-sdk-coregem我在从aws获取url时遇到错误以下是我的代码definitialize(bucket:,region:)@bucket=bucketclient=Aws::S3::Client.new(region:region)@signer=Aws::S3::Presigner.new(client:client)enddefsign(key,expires_in:3600)@signer.presigned_url(:get_object,bucket:@bucket,key:key,expires_in:expires_in)end我遇到了错误NoMet