草庐IT

ruby - Puma 服务器无故死机

我正在运行Puma2.8.2服务器来stub我的一些后端服务。有时Puma服务器会无缘无故地死掉。error.log中没有错误,下面是access.log的摘录:10.210.140.21--[15/Oct/201409:28:22]"GET/statusHTTP/1.1"200-0.0030-Gracefullystopping,waitingforrequeststofinish-Goodbye!===pumastartup:2014-10-1509:28:24+0100===10.210.140.21--[15/Oct/201409:28:24]"GET/statusHTTP/1

Ruby On Rails 模型、 View 和 Controller 之间的关系

根据我目前的理解,如果我必须描述Rails应用程序的各个组件如何协同工作以响应请求,我会说以下内容:1)路由确定哪些请求URL映射到哪些Controller方法。2)Controller方法从模型中获取信息并将该信息(以全局变量的形式)传递给相应的View模板。3)View模板使用存储在全局变量中的数据来构造最终响应。在上面的解释中,几个组件之间的关系是明确的,不可否认的;即:1)路由和Controller方法2)Controller方法和View模板其实上面的关系是一对一的。但是,模型类与其相邻组件类型(即Controller)的关系并不明确。是的,Controller从模型中检索信

ruby-on-rails - 使用多个数据库测试 Rails 应用程序

我有一个Rails应用程序,它在production环境中使用两个数据库,Users和Process。Users模型使用这个自定义的ActiveRecord类:classUserActiveRecord请注意,与特定数据库的连接是根据环境建立的。为了简化事情,在测试环境中,我有一个数据库,其中包含两个生产数据库中的所有表,我的database.yml文件看起来像这样:test:adapter:postgresqldatabase:db_testhost:localhostpool:...timeout:...username:...password:...test_users_db:a

ruby-on-rails - rspec Mongoid 范围适用于开发而不是测试

我有一个适用于Rails中的Mongoid对象的作用域,它在开发时效果很好,但在运行测试时效果不佳。它实际上在测试中根本不起作用。这是一个嵌入式文档。父级:classPersonincludeMongoid::Documentdefself.with_appointmentswhere(:appointments.not=>{'$size'=>0})endembeds_many:appointments,store_as:'Appointments',class_name:'Appointment'end嵌入的child:classAppointmentincludeMongoid::

ruby-on-rails - 使用 stock_quote gem 中的股票报价作为 acts_as_taggable gem 中的标签?

所以我正在使用acts_as_taggablegem提供的标签。这些帖子是我正在标记的内容。我怎么能说类似=>的东西(这里是伪代码)ifacollectionofPostshasatagwithacorrespondingStockQuote,displaythestockquote所以现在我有一个acts_as_taggable的Post资源。这是我的帖子索引操作现在的样子:defindex@stock=StockQuote::Stock.quote("symbol")ifparams[:tag]@posts=Post.tagged_with(params[:tag])else@po

ruby - 用于简单数组操作的慢速 Ruby

我按照Cormen的“算法导论”中的伪代码,在Ruby中创建了简单的插入排序实现:defsort_insert(array)(1...array.length).eachdo|item_index|key=array[item_index]i=item_index-1whilei>=0&&array[i]>keydoarray[i+1]=array[i]i-=1endarray[i+1]=keyendarrayend它有效,但执行速度非常慢。对于约20k个元素的数组array=((0..10_000).to_a*2).shuffle,排序大约需要20秒。我只测量这个方法调用的时间,没有

ruby-on-rails - 无法创建新的 Rails 项目 : `require' : cannot load such file --/config/boot (LoadError)

我正在尝试创建一个新的Rails项目,Jakes-Air:codeJakeWengroff$railsnewMyNewProject-T但我一直收到这个错误:script/rails:5:in`require':cannotloadsuchfile--/Users/JakeWengroff/config/boot(LoadError)fromscript/rails:5:in`'检查Ruby版本,ruby-v,我明白了ruby2.1.2p95(2014-05-08revision45877)[x86_64-darwin13.0]当我想检查Rails的版本时,rails-v,我得到了与我

ruby - Mongoid 3 中 Rails 模型的强一致性

我希望特定模型的所有数据库交互都通过集群中的mongo主节点,因此我将模型设置为使用强一致性。classPhotoincludeMongoid::Documentwithconsistency::strongfield:number,type:Integer#let'ssayaphotonumberisuniqueinthedbvalidate:unique_numberend但这似乎不起作用,因为当我保存两张非常靠近的照片时,我仍然遇到验证错误。photo1#dbhasnumber=1forthisobjectphoto1.update_attributes(number:2)pho

ruby - 如何在 Cucumber 的功能名称中使用空格

我正在使用Windows并尝试运行一个现有的功能包,该功能包最初是在MacOS上构建的,这允许他们通过使用带空格的"\"来解决问题。我正在使用Ruby2.2.3和Cucumber。功能名称包含空格,我无法更改它。我尝试使用""和''来绕过空白,但每次都有同样的问题。这是问题的一个例子。如果我运行:cucumberfeatures/'Namecontainingwhitespaces.feature'它工作正常。但是当我运行时:cucumber-pmy_profile和cucumber.yml包含:my_profile:features/'Namecontainingwhitespace

ruby-on-rails - Rails 4.1 和 4.2 之间 ActiveRecord Setter 的区别?

我们将我们的应用程序从Rails4.1.14升级到4.2.5.1并遇到了以下问题:string="SomeString"ar_model=SomeArModel.newar_model.some_attribute=string#nextlineistruefor4.1,butfailsfor4.2ar_model.some_attribute.object_id==string.object_id显然,对象setter会复制每个对象(如果我有一个数组,里面的每个对象也会被复制),我想知道,这是不是有意为之并且是某些新安全功能的一部分?更新我将ruby​​-2.2.2p95用于两个ra