草庐IT

is-at-bottom

全部标签

ruby-on-rails - rbenv : version `2.0.0' is not installed

我正在尝试使用Bundleinstall安装Gemfile内容,但出现错误rbenv:version`2.0.0'isnotinstalled我系统安装的ruby版本是:ruby2.1.2p95(2014-05-08revision45877)[i686-linux]和rbenv2.1.2(setby/home/jay/.rbenv/version)2.1.3Gemfile需要ruby"2.0.0"。谁能告诉我如何在不影响现有版本的情况下安装所需的版本。 最佳答案 您可以在这里找到很多信息:rbenvongithub列出所有可用的安

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 摩卡 : is there an equivalent to rspec-mocks' #and_call_original?

Rspec-mocks具有expect(some_object).toreceive(:some_method).and_call_original。我可以用Mocha做这个吗?如果可以,怎么做?some_object.expects(:some_method).......什么? 最佳答案 我相当确定没有办法做到这一点。浏览sourcecode,有评论提到完全替换了原来的方法。#Theoriginalimplementationofthemethodisreplacedduringthetestandthenrestoredatt

ruby - sinatra config.ru : what is the configure block for?

我将Sinatra与Apache和“经典”风格的Phusion-Passenger一起使用:#config.rurequire'sinatra'configuredo....endrequire'./app'runSinatra::Application我想定义一些东西。在配置block内部或外部定义它有什么区别?#config.rurequire'sinatra'#A)Definingloggerhererack=File.new("logs/rack.log","a+")useRack::CommonLogger,rack#B)GlobalvariableshereLOGGER=L

ruby-on-rails - ruby rails : How do you check if a file is an image?

如何检查文件是否为图像?我想你可以使用这样的方法:defimage?(file)file.to_s.include?(".gif")orfile.to_s.include?(".png")orfile.to_s.include?(".jpg")end但这可能有点低效而且不正确。有什么想法吗?(我正在使用回形针插件,顺便说一句,但我没有看到任何方法来确定文件是否是回形针中的图像) 最佳答案 请检查一次MIME::Types.type_for('tmp/img1.jpg').first.try(:media_type)=>"image"

ruby-on-rails - I18n : How to check if a translation key/value pairs is missing?

我正在使用RubyonRails3.1.0和I18ngem.我(正在实现一个插件)我想在运行时检查I18n是否缺少翻译键/值对,如果是,则使用自定义字符串。也就是说,我有:validates:link_url,:format=>{:with=>REGEX,:message=>I18n.t('custom_invalid_format',:scope=>'activerecord.errors.messages')}如果.yml文件中没有如下代码activerecord:errors:messages:custom_invalid_format:Thisisthetesterrormes

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 + 延迟作业 : Where is the correct place to store custom job classes?

我是delayed_job的新手,我开始编写自己的“自定义作业”。每个自定义作业基本上只是一个常规的ruby​​类,但我不确定这些自定义作业类通常存储在项目目录结构中的何处。我在考虑lib,但此时lib似乎是一个垃圾抽屉:/(不过也许没关系)谢谢!! 最佳答案 常见的方法是在app文件夹下创建jobs文件夹。但您唯一应该关心的是它们是您的文件,因此请以您觉得最适合自己的方式进行。 关于ruby-on-rails-Rails+延迟作业:Whereisthecorrectplacetosto

Ruby 'is_a?' 需要类或模块 (TypeError)

我正在尝试使用Ruby并尝试创建一个小型银行账户程序。当我运行这行与create_account一起运行的特定代码时:unless@response.is_a?Integer&&@response.to_str.length==4puts"Yourresponsemustbe4numbersinlength."create_accountelse@pin=@responseputs"Yourpinhasbeenset."end我收到这样的回复:bank_account.rb:24:in'is_a?':classormodulerequired(TypeError)frombank_ac