草庐IT

controlling-the-lifecycle-of-real

全部标签

ruby-on-rails - Capistrano gzip : stdin: unexpected end of file interruption

我在Capistrano部署方面遇到问题。部署过程因Gzip错误而被丢弃。它可以是什么?capflowdeploy*executing`flow'*executing`deploy'*executing`deploy:update'**transaction:start*executing`deploy:update_code'*getting(viacheckout)revisionto/tmp/20111214204507executinglocally:cp-R./tmp/20111214204507commandfinishedin413mscompressing/tmp/20

ruby-on-rails - 设计 Controller 如何改变布局?

这个问题在这里已经有了答案:differentlayoutforsign_inactionindevise(8个答案)关闭7年前。如何更改设计Controller中的布局?

ruby-on-rails - routes.rb - 不支持 Controller 名称

我遇到了一个很奇怪的问题。这是与routes.rb相关的部分:resources:playersmatch'/players/:userid',:to=>'Players#show'当您访问localhost:3000/players/1234时出现此错误:'Players'isnotasupportedcontrollername.Thiscanleadtopotentialroutingproblems.Controller中的相关代码:defshowbeginifPlayer.find_by(:uid=>:userid)then@playerattributes=Player.f

ruby-on-rails - rails : Prevent will_paginate from calling #count of ActiveRelation

当我向will_paginate传递一个ActiveRelation时,它总是调用它的#count方法并访问数据库以找出项目的总数。但是这个操作需要时间,而且我已经缓存并准备好了总数。我可以将这个预先计算的计数传递给will_paginate并阻止它访问数据库吗?我尝试了:count选项,但它作为选项传递给了ActiveRecord:active_relation.paginate(page:2,per_page:100,count:total_count)谢谢!:) 最佳答案 通过:total_entries传递缓存计数解决了问题

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 - 动态生成一个 `link_to` 到 Controller Action `edit`

我正在使用RubyonRails3.0.7,我想生成一个link_to到Controller操作edit,动态。我必须在部分模板中使用它,但问题是我正在为不同的模型数据呈现相同的部分模板(也就是说,我在其中传递了不同类实例的局部变量)。所以我不能使用路由“神奇的RoR方式”`edit__path()`.我想做如下的东西:link_to(@resource_class_instance,:action=>'edit')#Thisexampleiswrong,butitsuggeststheidea这可能吗?如果是这样,我该怎么做? 最佳答案

ruby-on-rails - rails : replacing try with the Null Object Pattern

在我的大多数应用程序中,我都有一个current_user方法。为了避免像current_user.name这样的情况出现异常,其中current_user是nil,rails提供了try方法。这个问题是我需要记住在current_user可能是nil的地方使用try。我想使用NullObject模式来消除这种额外的开销。classNullUserdefmethod_missing(method_name,*args)nilendenddefcurrent_userreturnNullUser.newunlessUserSession.find@current_user||=UserS

ruby-on-rails - 带分号的字符串在 RubyMine 中产生 "unterminated string meets end of file"

在RubyMine调试器中,只需在watch中输入:';'或";"我收到错误:"unterminatedstringmeetsendoffile"这是为什么?据我所知,它不会发生在Rails控制台中,并且与RubyMine没有任何关系。 最佳答案 这是Ruby调试器与Ruby解释器具有不同解析规则的结果。事实上,从irb或ruby命令调用的常规Ruby调试器表现出相同的行为。然而,解决方法很简单:要创建一个由单个分号组成的字符串文字,只需使用反斜杠将其转义即可:$irb>require'debugger'=>true>debugge

ruby-on-rails - 为什么我的 Controller 的实例变量在 View 中不起作用 (Rails)

我想向我的Controller添加几个实例变量,因为在多个操作的View中需要相关变量。但是,下面的示例并不像我预期的那样工作。classExampleController据我了解,Rails从Controller获取实例变量并使它们在View中可用。如果我在操作方法中分配相同的变量,它工作正常-但我不想做两次。为什么我的方法不行?(注意:这是一个有点垃圾的例子,但我希望它有意义)编辑:我在这里找到了这个问题的答案:WhendoRubyinstancevariablesgetset?编辑2:何时是使用before_filter和初始化方法等过滤器的最佳时机?

ruby-on-rails - rails : Omniauth - "The parameter app_id is required"

我正在按照这个railscast教程在我的rails项目上为facebook身份验证设置omniauth:http://railscasts.com/episodes/360-facebook-authentication?autoplay=true.我只用了4分钟,到目前为止我所做的就是捆绑gemomniauth-facebook并添加,omniauth.rbOmniAuth.config.logger=Rails.loggerRails.application.config.middleware.useOmniAuth::Builderdoprovider:facebook,ENV