草庐IT

not_matched

全部标签

ruby - 获取名称错误 : `format' is not allowed as an instance variable name when testing instance variable with rspec

我有以下测试:let(:client){Descat::Client.new}describe'poblacio'doit'shouldsetformatcorrectly'doclient.poblacio('v1','json','dades')expect(client.instance_variable_get(:format)).toeq('json')endend我有以下正在测试的代码:moduleDescatclassClientBASE_URL='http://api.idescat.cat/'definitialize(attributes={})attributes

ruby - 我在 Mac OS X 上收到 "RVM is not a function"错误,并且没有发布的解决方案有效

我在MacOSx10.8.2(“MountainLion”)上,我成功安装了RVM1.17.8及其依赖项。我可以使用它来使用rvminstall1.9.2安装Ruby版本,但我无法执行rvmuse没有收到此错误:RVMisnotafunction,selectingrubieswith'rvmuse...'willnotwork.Youneedtochangeyourterminalemulatorpreferencestoallowloginshell.Sometimesitisrequiredtouse`/bin/bash--login`asthecommand.Pleasevis

ruby - Regexp.last_match 线程安全吗?

这是我正在查看的代码:defmethod_missing(id,*args)returnself.find(Regexp.last_match(1),args[0])ifid.id2name=~/find_by_(.+)/raiseNoMethodErrorend如果我有多个线程调用Regexp.last_match会怎样?如果我有多个线程使用method_missing方法调用对象会怎样? 最佳答案 Ruby1.9.2平台文档声明调用Regexp.last_match等同于读取特殊的$~全局变量。摘自“TheRubyProgram

Ruby Gems 返回 "command not found"

Ubuntu9.10刚刚安装了newgemgeminstallnewgem当我尝试newgemnew_project我明白了adam@adam-ubuntu:~$newgemnewprojectnewgem:commandnotfound我通过echo$PATH检查了我的路径adam@adam-ubuntu:~$echo$PATH/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/adam/.gem和我的gem环境adam@adam-ubuntu:~$gemenvironmentRu

ruby 正则表达式 : replace non-word chars that are not space chars

如何替换所有也不是空格字符(\s)的非单词字符(\W)?这是所需的功能:"the(quick)!brown\nfox".gsub(regex,"#")=>“#quick##brown\nfox” 最佳答案 "the(quick)!brown\nfox".gsub(/[^\w\s]/,"#")通过使正则表达式替换任何不是单词字符或空格字符的内容。 关于ruby正则表达式:replacenon-wordcharsthatarenotspacechars,我们在StackOverflow上找到

ruby-on-rails - Rails + Twitter Bootstrap : File to import not found or unreadable: twitter/bootstrap

我正在尝试使用TwitterBootstrap(gemtwitter-bootstrap-rails)设置Rails应用程序,但我仍然无法克服错误Filetoimportnotfoundorunreadable:twitter/bootstrap.我在gem的官方Github上发现了这个问题,但是那里的解决方案都对我不起作用。这是我的设置:gem文件gem"twitter-bootstrap-rails"gem'font-awesome-rails'gem'sass-rails','~>3.2.3'group:assetsdo#gem'sass-rails','~>3.2.3'gem'

ruby-on-rails - rails 5, "nil is not a valid asset source"

我刚刚升级到Rails5,在尝试显示图像时遇到了一个奇怪的问题。我有Rails4的确切代码:但升级后我得到:nilisnotavalidassetsource在升级到Rails5之前,我没有遇到任何类似的问题。这里可能有什么问题?会不会是其他原因而不是Rails升级问题? 最佳答案 问题是我试图显示一张不存在的图片。添加unlessarticle.image.blank?解决了这个问题:编辑:在Rails4中,这将不会毫无错误地呈现任何内容,而在Rails5它会引发错误。所以这实际上是一个升级问题。非常感谢@BookOfGreg指出

ruby-on-rails - rails rbenv : rails: command not found

我最近从RVM转移到Rbenv并且在尝试执行rails时出现如下错误Pauls-Air:~$railsrbenv:rails:commandnotfoundThe`rails'commandexistsintheseRubyversions:2.1.2 最佳答案 在ruby​​版本中通过命令行安装gem后,您必须按照文档here中的描述执行rbenvrehash和here例如:$rbenvinstall2.2.0$geminstallbundler$rbenvrehash$geminstallrails$rbenvrehash

ruby-on-rails - railstutorial.org 中的 SessionsHelper : Should helpers be general-purpose modules for code not needed in views?

railstutorial.org有一个让我觉得有点奇怪的建议。Itsuggeststhiscode:classApplicationControllerincludeSessionsHelper使方法在ApplicationController中可用,是的,但它也使它们在任何View中都可用。我知道身份验证/授权是交叉的,但这真的是最好的地方吗?在我看来,这可能范围太广了。将实现有条件重定向(如railstutorial.org示例所做的)的before_filter的代码放在更通常包含View助手的模块中似乎令人惊讶。将View中不需要的功能放在ApplicationControl

javascript - rake 数据库 :create - Could not find a JavaScript runtime

这是我得到的错误:sergio@sergio-VirtualBox:~/blog$rakedb:createrakeaborted!CouldnotfindaJavaScriptruntime.Seehttps://github.com/sstephenson/execjsforalistofavailableruntimes.(Seefulltracebyrunningtaskwith--trace)sergio@sergio-VirtualBox:~/blog$所以经过一些搜索,我似乎需要为Ruby安装一个Javascript运行时。许多不同的选项之间有区别吗?看来Node.js是