草庐IT

add_custom_command

全部标签

ruby - 检查 "command"的输出应该包含 NilClass 的意外崩溃

为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar

ruby-on-rails - 从 ActiveAdmin has_many 表单助手中删除 "Add new"按钮

我在事件管理员编辑页面中有嵌套资源,但我只想允许管理员编辑现有资源的内容,而不是添加新的嵌套资源。我的代码看起来像这样:formdo|f|f.inputsdof.input:authorf.input:contentf.has_many:commentsdo|comment_form|comment_form.input:contentcomment_form.input:_destroy,as::boolean,required:false,label:'Remove'endendf.actionsend但它在输入下添加了“添加新评论”按钮。我怎样才能禁用它,并只为主窗体保留f.ac

ruby-on-rails - `require' : cannot load such file -- rails/commands

我是Rails的新手,我刚刚使用以下命令从头开始在MacOSSierra上安装了Rails:$gpg--keyserverhkp://keys.gnupg.net--recv-keys409B6B1796C275462A1703113804BB82D39DC0E3\curl-sSLhttps://get.rvm.io|bash-sstable--ruby$rvm-vrvm1.29.1(latest)byMichalPapis,PiotrKuczynski,WayneE.Seguin[https://rvm.io/]$ruby-vruby2.4.0p0(2016-12-24revisio

ruby-on-rails - 脚本/服务器 custom_require.rb :36:in `require' : cannot load such file -- test/unit/error (LoadError)

我有一个基于1.8.7构建的应用程序,我正尝试在1.9.3的系统上启动它当我运行脚本/服务器时,我得到:/usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in`require':cannotloadsuchfile--test/unit/error(LoadError)from/usr/local/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in`require'我的服务器脚本如下所示:#!/usr/bin/envrubyrequireFile.expand_path('../.

ruby - 为 IO::popen 拯救 "command not found"

当我将IO::popen与不存在的命令一起使用时,我在屏幕上打印了一条错误消息:irb>IO.popen"fakefake"#=>#irb>(irb):1:commandnotfound:fakefake有什么方法可以捕获此错误,以便我可以在脚本中进行检查? 最佳答案 是:升级到ruby​​1.9。如果您在1.9中运行它,则会引发Errno::ENOENT,您将能够拯救它。(编辑)这是在1.8中的一种hackish方式:error=IO.pipe$stderr.reopenerror[1]pipe=IO.popen'qwe'#

ruby-on-rails - rails 5 : Autoloading with custom folders not working

我有这门课:#app/events/new_request.rbclassEvents::NewRequestend然后我将该文件夹添加到自动加载:#config/application.rbconfig.autoload_paths+=%W(events/)当运行railsc时:>Events::NewRequestNameError:uninitializedconstantEvents问题是,如果我在定义类时不使用命名空间“Events”,它会成功自动加载类。 最佳答案 moduleSandboxclassApplicatio

ruby-on-rails - Rails add_index 算法 : :concurrently still causes database lock up during migration

为了防止在迁移到生产站点期间出现数据库事务错误,我们遵循了https://github.com/LendingHome/zero_downtime_migrations中列出的建议。(具体由https://robots.thoughtbot.com/how-to-create-postgres-indexes-concurrently-in概述),但在特别大的表上创建索引期间,即使是索引创建的“并发”方法也会锁定表并导致该表上的任何ActiveRecord创建或更新导致各自的事务失败有PG::InFailedSqlTransaction异常。下面是我们运行Rails4.2(使用Acti

ruby 选项解析器 : hiding help text for a command option

Ruby“OptionParser将根据此描述自动为您生成帮助屏幕”[http://ruby.about.com/od/advancedruby/a/optionparser.htm]有没有办法删除命令选项的帮助文本。我可以使用隐藏命令,但有一个命令选项(开关)并隐藏其帮助上下文。 最佳答案 我能够为此拼凑出一个不太优雅的解决方案。它将隐藏主帮助屏幕中的选项,听起来它可能符合您的需要:require'optparse'options={}OptionParser.newdo|opts|opts.banner="Usage:#{$0}

ruby-on-rails - Rails 4.2 Action Controller :BadRequest custom error message

如果验证失败或参数丢失,我想从我的Controller返回400-错误请求。所以在我的Controller中如果有ifparams["patch"].nil?thenraiseActionController::BadRequest.new("TheJsonbodyneedstobewrappedinsidea\"Patch\"key")end我在我的应用程序Controller中发现了这个错误:rescue_fromActionController::BadRequest,with::bad_requestdefbad_request(exception)renderstatus:4

ruby-on-rails - rails : Loading custom class from lib folder in controller

我创建了一个名为lib/services/my_service.rb的文件。#/lib/services/my_service.rbclassMyService...end我想在app/controllers/my_controller中使用它classMyController我收到一个错误消息,指出MyService是一个未初始化的常量。我尝试用导入它require'/lib/services/my_service.rb'但是我得到了cannotloadsuchfile--/lib/services/my_service.rb编辑:我尝试使用application.rb自动加载con