草庐IT

The Digital Journey of Microsoft AI & IoT Insider Lab and Partners

全部标签

ruby-on-rails - rails 生成 rspec :install config/environments/development. rb:1:in `<top (required)>': 未定义方法 `configure'

首先,这是我的版本:Greg-Nowickis-MacBook-Pro:sample_appGreg_Nowicki$ruby-vruby2.0.0p451(2014-02-24revision45167)[x86_64-darwin13.1.0]Greg-Nowickis-MacBook-Pro:sample_appGreg_Nowicki$rails-vRails4.0.4我正在学习HartlRails教程并安装rspec进行测试。我已将gem'rspec-rails'添加到我的gemfile中,当我运行railsgeneraterspec:install时,这就是我得到的:Gre

ruby - Ruby 中的 "method"方法有什么意义?

在Ruby中,有“method”方法,它创建一个方法对象,然后您可以将其视为Proc。如果您想进行元编程,这很有用:deffoobar(method_as_a_string)2.method(method_as_a_string).call(2)endfoobar("+")=>4foobar("-")=>0但是,通常情况下,如果您想进行这样的元编程,您会使用send而不是方法...deffoobar(method_as_a_string)2.send(method_as_a_string,2)endfoobar("+")=>4foobar("-")=>0Ruby中的“方法”方法有什么意

ruby - Nokogiri 'not' 选择器

Nokogiri中是否有一种方法可以选择所有与选择器不匹配的元素。在jQuery中我会使用::not(*[@class='someclass'])但是下面的代码给我一个xpath语法错误dom=Nokogiri::HTML(@file)dom.css(":not(*[@class='someclass'])") 最佳答案 InCSS3,:not()takesaselectorlikeanyother,所以它会是:dom.css(":not(.someclass)")(未经测试,但选择器是正确的)

Ruby 的 'or' 与 '||'

这个问题在这里已经有了答案:关闭11年前。PossibleDuplicate:Differencebetween“and”and&&inRuby?Ruby:differencebetween||and'or'我有这段代码(类似这样的东西)foo=nilor4我希望foo成为第一个值(可以是nil)或默认值4。当我在irb中测试时,输出是我所期望的它是。愚蠢的我,我后来没有检查foo的值。一段时间后,我开始注意到我的代码中存在一些错误,直到我在irb中检查foo的值后我才发现问题,哦,令人惊讶的是,nil而不是预期的4。关于or与||的故事是什么?他们应该作为替代品工作吗?使用或代替||

ruby - 无法激活 susy-2.1.1,因为 sass-3.2.17 与 sass 冲突 (~> 3.3.0)

我已经安装了最新版本的compass、sass和susy。但我仍然收到此错误:Unabletoactivatesusy-2.1.1,becausesass-3.2.17conflictswithsass(~>3.3.0)有人知道这个Ruby是如何工作的吗?这是我安装的gem的列表:***LOCALGEMS***CFPropertyList(2.2.0)chunky_png(1.3.0)compass(0.12.4)compass-core(1.0.0.alpha.19)compass-import-once(1.0.4)compass-rails(1.1.3)fssm(0.2.10)l

ruby-on-rails - OSX 10.7.5 - Ruby on Rails LoadError : Could not open library 'sodium' : dlopen(sodium, 5)

输入rakedb:create后我得到:LoadError:Couldnotopenlibrary'sodium':dlopen(sodium,5):imagenotfound.Couldnotopenlibrary'libsodium.dylib':dlopen(libsodium.dylib,5):imagenotfound这里还有一些输出。/Users/Mao/.rvm/gems/ruby-2.0.0-p451/gems/ffi-1.9.3/lib/ffi/library.rb:133:in`blockinffi_lib'/Users/Mao/.rvm/gems/ruby-2.0

ruby-on-rails - 使用 Pow 作为服务器在 RubyMine 中调试 - Ruby 2.1.1 + Rails 4

我已经开始使用RubyMine6。我正在处理Rails4、Ruby2.1.1项目。我无法找到如何使用Pow作为服务器调试到RubyMine。你能给我指明正确的方向吗? 最佳答案 我能够使用远程调试从RubyMine进行调试。我正在使用RubyMine6、Rails3、Ruby2.1.1。首先创建一个.powenv文件并添加:exportRUBY_DEBUG_PORT=1234exportPOW_WORKERS=1将以下gem添加到您的Gemfile:gem'ruby-debug-ide'gem'debase'创建一个新的初始化器st

Ruby & Syslog & 自定义工具

我是syslog的新手。我们决定使用系统日志来跟踪Rails应用程序中的一些特殊事件。问题是我不想使用默认的/var/log/system.log文件,而是使用自定义文件,例如/var/log/myapp_events.log.我看到我必须像这样在/etc/syslog.conf中定义我自己的设施:myapp_events.*/var/log/myapp_events.log重新启动syslogd后,我发现我可以直接在bash控制台中使用它:syslog-s-kFacilitymyapp_eventsMessage"thisismymessage"该消息按预期出现在/var/log/m

ruby - rspec: 未定义的方法 'double'

我正在尝试创建一个替身,但我一直收到此错误:undefinedmethod`double'for#(NoMethodError)我怀疑问题与我的规范助手有关,所以我在下面添加了我的规范助手:$LOAD_PATH.unshift(File.join(File.dirname(__FILE__),'..','lib'))$LOAD_PATH.unshift(File.dirname(__FILE__))require'rspec'require'webmock/rspec'includeWebMock::APIincludeWebMock::MatchersDir["#{File.dirn

ruby - Rubocop 规则 : Never use 'do' with multi-line 'while

我有以下代码#coloursarandomcellwithacorrectcolourdefcolour_random!whiletruedocol,row=rand(columns),rand(rows)cell=self[row,col]ifcell.empty?thencell.should_be_filled??cell.colour!(1):cell.colour!(0)breakendendend做什么并不重要,尽管它应该很明显。关键是Rubocop给了我一个警告Neveruse'do'withmulti-line'while为什么我不应该那样做?那我该怎么办呢?