草庐IT

scheduling-a-timer-task-to-run-re

全部标签

ruby-on-rails - rails : How to test if an attribute of a class object is required in the model policy?

简单地说,我有一个模型用户,其中包含名称、电子邮件和评论作为属性。validates_presence_of:namevalidates_presence_of:email所以“姓名”和“电子邮件”是必需的,但不是“评论”。my_user=User.new我想找到一种方法来测试像my_user.name.required?或User.name.required?类似的东西。我的目标是创建一个表单,并根据该项目是否设置为“validates_presence_of”,将特定类动态添加到表单项目span或td我试图搜索它,但没有找到任何相关信息。有没有简单的方法可以做到这一点?谢谢

arrays - Ruby 数组上的未定义方法 'to_h'

根据RubyArraydocumentation,有一个方法to_h可以用来将数组转换为散列,只要数组的每个元素都是另一个包含两个元素的数组。来自同一文档的以下示例p[[:foo,:bar],[1,2]].to_h但是,当我运行上面的代码时,出现了这个错误:irb(main):001:0>p[[:foo,:bar],[1,2]].to_hNoMethodError:undefinedmethod`to_h'for[[:foo,:bar],[1,2]]:Arrayfrom(irb):1fromE:/RubyInstall/bin/irb:12:in`'irb(main):002:0>我的

ruby-on-rails - postgresql 数据库错误 : Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

当我运行rakedb:migrate或运行railss命令时,我得到同样的错误:Error:couldnotconnecttoserver:NosuchfileordirectoryIstheserverrunninglocallyandacceptingconnectionsonUnixdomainsocket"/var/run/postgresql/.s.PGSQL.5432"?当我尝试railss时,浏览器出现错误。这是我的database.ymldefault:&defaultadapter:postgresqlencoding:unicodepool:5development

ruby-on-rails - 正在尝试安装 libv8, "failed to build gem native extension"

我使用的是W764位。简单地说,当我输入时:C:\Sites>geminstalllibv8我得到这个结果:TemporarilyenhancingPATHtoincludeDevKit...Buildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallinglibv8:ERROR:Failedtobuildgemnativeextension.C:/RailsInstaller/Ruby1.9.3/bin/ruby.exeextconf.rbcreatingMakefilewhich:nogmakein("myPAT

ruby-on-rails - Rails bundler : how to undo bundle package?

如何撤销bundlepackage?我删除了vendor/cache中的所有内容,但是当我运行bundleinstall时它又重新安装在那里。 最佳答案 根据这个答案:https://stackoverflow.com/a/9471980/219883必须删除隐藏的.bundle目录,然后重新运行bundleinstall-否则会继续添加vendor/cache每次返回目录。 关于ruby-on-rails-Railsbundler:howtoundobundlepackage?,我们在

ruby-on-rails - ruby rails : no such file to load -- openssl on RedHat Linux Enterprise

我正在尝试执行“rakedb:migrate”并收到错误消息“没有要加载的文件--openssl”。“openssl”和“openssl-devel”包都已安装。Debian或Ubuntu上的其他人似乎能够通过安装“libopenssl-ruby”来摆脱这种情况,这不适用于RedHat。有没有人遇到过这个问题并有解决方案? 最佳答案 升级到8.10后,我在Ubuntu上遇到了这个问题。Ubuntu的解决方案是sudoapt-get安装libopenssl-ruby 关于ruby-on-r

ruby - rake --tasks 完整描述(未删减)

也许是那些代码18之一,但是当我在我的Rakefile上运行rake-T时,我的任务的长描述总是被删掉。有什么方法可以显示完整的描述而不必缩短描述?谢谢 最佳答案 格式略有不同(描述从下一行开始而不是当前行的注释),但这将为您提供完整的描述:rake-D此外,如果您真的想要其他格式,您可以将输出通过管道传输到cat:rake-T|cat 关于ruby-rake--tasks完整描述(未删减),我们在StackOverflow上找到一个类似的问题: https:

ruby - Ruby 中的 i.to_s 是什么意思?

我想理解我在Google中找到的一段代码:i.to_s在上面的代码中,i是一个整数。根据我的理解i正在被转换成一个字符串。是真的吗? 最佳答案 更好的说法是这是一个返回整数i的字符串表示形式的表达式。整数本身不会改变。#迂腐。在内部>>54.to_s=>"54">>4598734598734597345937423647234.to_s=>"4598734598734597345937423647234">>i=7=>7>>i.to_s=>"7">>i=>7 关于ruby-Ruby中的i

ruby - Heroku 应用程序无法启动 - `require' : no such file to load -- sinatratestapp (LoadError)

我正在尝试使用bamboo-mri-1.9.2堆栈运行我的Heroku应用程序。当然,它在Ruby1.9.2上本地运行良好。但是在生产环境中,它在执行config.ru的启动过程中崩溃,如下所示:require'sinatratestapp'runSinatra::Application我的.gems文件:sinatra--version'>=1.0'应用程序本身为sinatratestapp.rb:require'rubygems'require'sinatra'get'/'do"HellofromSinatraonHeroku!"end这就是我在项目中得到的所有内容,并尝试在Her

ruby - nokogiri 不会安装 - 错误 : Failed to build gem native extension

这个问题在这里已经有了答案:`require':nosuchfiletoload--mkmf(LoadError)(10个答案)关闭9年前。在ubuntu12.04上,我得到以下信息。sudoapt-getinstalllibxml2libxml2-devlibxsltlibxslt-devsudogeminstallnokogiriBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingnokogiri:ERROR:Failedtobuildgemnativeextension./usr/bin/ruby