草庐IT

with-config-file-scan-dir

全部标签

ruby-on-rails - 如何测试依赖: :destroy with RSpec?

我想测试我的User模型关联has_many:projects,dependent::destroy现在已经走了这么远:it"destroysdependentprojects"douser=FactoryGirl.build(:user)project=FactoryGirl.build(:project)user.projects但这给出了一个错误:Failure/Error:expect(Project.count).tochange(-1)ArgumentError:`change`requireseitheranobjectandmessage(`change(obj,:ms

ruby-on-rails - ruby 正则表达式错误 : incompatible encoding regexp match (ASCII-8BIT regexp with UTF-8 string)

我遇到了两个错误,都与编码有关并且都相关。我在启动WEBrick时遇到的第一个错误(技术上是警告):/Users/USERNAME/example/config/initializers/bb-ruby.rb:54:warning:invalidUnicodeProperty\P:/\:\-?\P/它所指的行是:/\:\-?\P/,这只是一些正则表达式,最终是这个block的一部分:@@tags['Razzing']=[/\:\-?\P/,'','Razzing',':P',:razzing]然后,我在解析一些字符串时也得到了以下错误(大概是由于同一行)...Encoding::Com

ruby - each_with_index_do 索引从 1 开始

我在Rails应用程序的View上使用ruby​​迭代器,如下所示:...我想加上1..而不仅仅是说:@document.data会得到让上面的索引从1开始的技巧。但是,遗憾的是,上面的代码索引仍然是0到data.length(实际上是-1)。那么我做错了什么,我需要索引等于1-data.length...不知道如何设置迭代器来执行此操作。 最佳答案 除非你使用像1.8这样的旧Ruby(我认为这是在1.9中添加的,但我不确定),你可以使用each.with_index(1)来获得1-基于枚举器:在你的情况下它会是这样的:...

ruby-on-rails - 尝试在测试中运行 rails c 时获取 config.eager_load 设置为 nil

我正在尝试运行Rails(4.1.2)控制台railscRAILS_ENV=test我得到这个:>config.eager_loadissettonil.Pleaseupdateyour>config/environments/*.rbfilesaccordingly:>>*development-setittofalse*test-setittofalse(unless>youuseatoolthatpreloadsyourtestenvironment)*production->setittotrue>>/Users/xxxxxx/.rvm/gems/ruby-2.2.2/gems

ruby-on-rails - "config.assets.debug"设置到底是做什么的?

我已经开始开发简单的Rails应用程序。经过几个小时的工作,我注意到删除的css不知何故仍应用于网页。为了解决这个问题,我多次执行了以下操作:停止/启动服务器使用rails服务器使用torquebox服务器删除浏览器缓存但没有任何变化。这很奇怪——应用了新的css定义,但我删除的那些定义仍然存在。所以,我放弃了,决定创建新项目。我已经设置了新项目(它的脚手架与第一个项目相同),当我打开其中一个View时,旧项目的样式也被应用了。我决定再次调查http://guides.rubyonrails.org/asset_pipeline.html并找出那个设置#Expandsthelinesw

ruby-on-rails - 如何配置 config.yml 以便我可以安装 devkit?

MicrosoftWindows[Version6.1.7601]Copyright(c)2009MicrosoftCorporation.Allrightsreserved.C:\Users\Aaron>cd/DevKitThesystemcannotfindthepathspecified.C:\Users\Aaron>cd\DevKitC:\DevKit>rubydk.rbinitInitializationcomplete!Pleasereviewandmodifytheauto-generated'config.yml'filetoensureitcontainstheroo

关于Document mapping type name can‘t start with ‘_‘, found: [_update]

在修改elasticsearch时,用_update进行局部修改,修改失败,报错{    "error": {        "root_cause": [            {                "type": "invalid_type_name_exception",                "reason": "Document mapping type name can't start with '_', found: [_update]"            }        ],        "type": "invalid_type_name_exce

ruby - 如何使用 Dir 类删除非空目录?

Dir.delete("/usr/local/var/lib/trisul/CONTEXT0/meters/oper/SLICE.9stMxh")导致此错误:Directorynotempty-/usr/local/var/lib/trisul/CONTEXT0/meters/oper/SLICE.9stMxh如何删除一个目录,即使它仍然包含文件? 最佳答案 Dir是不可能的(除非自己遍历目录或使用Dir.glob并删除所有内容)。你应该使用require'fileutils'FileUtils.rm_r"/usr/local/va

ruby-on-rails - 安装调试器时出错 : Failed to build gem native extension with ruby-1. 9.3-p362

尝试为新项目运行bundle时,遇到以下错误:Installingdebugger(1.2.2)withnativeextensionsGem::Installer::ExtensionBuildError:ERROR:Failedtobuildgemnativeextension.C:/Ruby193/bin/ruby.exeextconf.rbcheckingforrb_method_entry_t.called_idinmethod.h...nocheckingforrb_control_frame_t.method_idinmethod.h...nocheckingforrb_

ruby - 冒号(:) appears as forward slash (/) when creating file name

我正在使用日期和时间来标记我正在创建的新文件,但是当我查看该文件时,冒号是一个正斜杠。我正在使用10.7+在Mac上开发这是我使用的代码:File.open("#{time.hour}:00,#{time.month}-#{time.day}-#{time.year}","a")do|mFile|mFile.syswrite("#{pKey}-#{tKey}:\n")mFile.syswrite("Itemsclosed:#{itemsClosed}|Totalitems:#{totalItems}|Percentclosed:%#{pClosed}\n")mFile.syswrite