草庐IT

ruby-on-rails - 运行 Rspec 时出现 "No such file to load"错误

MacOS10.4rspec(1.1.11,1.1.4,1.1.3,0.5.15)rspec-rails(1.1.11)rspec_generator(0.5.15)rails2.2.2ruby1.8.6(2007-03-13patchlevel0)[universal-darwin8.0]创建了一个新项目...$railsmyproject将rspec安装到项目中...$script/generaterspec生成资源...$script/generaterspec_scaffoldmyresourcename:stringdescription:text试图运行规范...$rake

ruby - __LINE__ 和 __FILE__ 常量在 Ruby 中是如何实现的?

似乎__FILE__和__LINE__常量会随着当前文件和正在执行的行号动态更新,我想知道Ruby中的行为是如何实现的?源码我已经grep过了,但是__LINE__和__FILE__出现的杂音太多了,不知道有没有人能帮我指出源码并提供了解其行为的线索。用Rubinis或MRI解释都可以。 最佳答案 __FILE__和__LINE__都被文字替换了directlyintheparser:casekeyword__FILE__:returnNEW_STR(rb_external_str_new_with_enc(ruby_sourcef

ruby-on-rails - 验证失败 : Upload file has an extension that does not match its contents

我正在使用回形针gem上传文件。我的回形针gem版本是paperclip-4.1.1。上传文件时抛出Validationfailed:Uploadfilehasanextensionthatdoesnotmatchitscontents.我正在尝试上传xlsx文件。而且我已经在模型content_type中提到了这一点。validates_attachment_content_type:upload_file,:content_type=>%w(application/mswordapplication/vnd.ms-officeapplication/vnd.ms-excelappl

ruby-on-rails - 带@global gem 的 Ruby/RVM - bundle 运行失败,显示 `require' : cannot load such file — bundler (LoadError)

我学习了1个月的linux。当我尝试从MigratingfromMySQLtoPostgresonHeroku开始执行所有步骤时我遇到无法处理的错误。当我尝试从源代码安装mysqltopostgresgem时:$gitclonehttps://github.com/maxlapshin/mysql2postgres.git$cdmysql2postgres$bundleinstall$gembuildmysqltopostgres.gemspec$sudogeminstallmysqltopostgres-0.2.20.gem我在$bundleinstall上有一个错误:/home/f

ruby - 化简多个is_a?调用对象

如何使用迭代器重写这一行?actor.inspectifactor.is_a?Array||actor.is_a?Hash我的尝试无效:actor.inspectif[Array,Hash].each{|c|actor.is_a?c} 最佳答案 如果你想匹配精确的类(而不是后代),你可以使用:[Hash,Array].member?a.class我认为您应该解释一下您究竟需要实现什么。也许您唯一需要检查的是您的对象是否是Enumerable,或者即使它是respond_to?某个特定方法。

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我试图搜索它,但没有找到任何相关信息。有没有简单的方法可以做到这一点?谢谢

ruby-on-rails - Rails 服务器错误 : Ruby version is 1. 8.7,但您的 Gemfile 指定了 1.9.3

我输入了一个现有的ruby​​应用程序,然后输入:$rails想在这里启动railsserver。但它说:您的Ruby版本是1.8.7,但您的Gemfile指定为1.9.3其实我有一个1.8.7,但是我把它删掉了。如果我这样做:$ruby-v它说:ruby1.9.3p286(2012-10-12修订版37165)[x86_64-darwin11.4.2]所以我不知道该如何解决。你能帮我个忙吗? 最佳答案 如果您使用rvm,运行这个:$rvmuse1.9.3 关于ruby-on-rails

ruby - Rspec——需要 stub File.open 在另一个文件中被调用

在我的测试中,我使用一些参数初始化了一个名为Package的新类。在这个类的初始化中,我打开了一个文件,该文件在我的远程机器上可用,但在本地通常不存在。我想知道如何在我的测试中stub该方法。我正在使用rspec和mocha。我试过类似的东西:File.stubs(:open).with(:file).returns(File.open("#{package_root}/test_files/test.yml"))在我的测试中初始化Package之前,我有这一行。我遇到了这个错误:unexpectedinvocation:File.open('package/test_files/te

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 - 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