草庐IT

ruby-on-rails - 修复 "ruby installation is missing psych"错误?

我正在运行Rubyruby​​1.9.3p125,但我不断收到此错误,这让我无法在Rails中进行任何类型的开发。Itseemsyourrubyinstallationismissingpsych(forYAMLoutput).Toeliminatethiswarning,pleaseinstalllibyamlandreinstallyourruby.我用Google搜索了一下,似乎尝试了所有方法,但似乎没有任何效果。我真的很想开始一些新项目,但似乎无法绕过这个障碍。非常感谢任何帮助! 最佳答案 我在使用rvm安装ruby​​1.

ruby-on-rails - rails : validating a field is present only if another is present

我有一个模型,其中有两个字段在技术上可以为空。字段名称是:is_activated和:activated_at。:activated_at仅在:is_activated设置为true时才需要。如果:is_activated为false,则不需要存在。在Rails中将此验证直接设置到ActiveRecord中的合适方法是什么? 最佳答案 您可以使用Proc在:activated_at验证器上。validates:activated_at,:presence,if:Proc.new{|a|a.is_activated?}推荐阅读:htt

ruby-on-rails - rails : Ensure only one boolean field is set to true at a time

我有一个Logo模型,它的字段名称为:字符串,默认为bool值。我希望true值是唯一的,以便一次只能将数据库中的一项设置为true。如何在我的Controller中设置更新和新操作以将Logo的所有其余值设置为false?假设我有以下设置在我的数据库中模特标志名称:字符串|默认值:bool值|项目1|是的|项目2|假|第3项|假|如果我将Item2默认值更改为true,我希望它遍历所有Logo并将其余Logo设置为false,因此一次只有一个为true,所以它看起来像这样。名称:字符串|默认值:bool值|项目1|假|项目2|是的|第3项|假|提前感谢您的帮助。

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