草庐IT

inversion-of-control

全部标签

ruby-on-rails - 未初始化常量 "Controller Name"

我的路由/资源和Controller有错误。我在routes.rb中有以下内容:#routes.rbresources:usersdoresource:scheduleend我在controllers/users/中设置了一个schedule_controller.rb,我认为它应该是:classUsers::ScheduleController运行rake:routes显示user_schedulePOST/users/:user_id/schedule(.:format)schedules#createnew_user_scheduleGET/users/:user_id/sche

ruby-on-rails - Rails Unicorn - 启动请求和到达 Controller 之间的延迟

我正在使用Unicorn作为我的Rails应用程序的应用程序服务器,并且我试图弄清楚为什么有时在请求开始和请求到达我的Controller之间会有一个重要的(>5秒)延迟.这是我的production.log打印出来的:StartedGET"/search/articles.json?q=mashable.com"for138.7.7.33at2015-07-2314:59:19-0400**Parameters:{"q"=>"mashable.com"}Searchingarticlesforkeyword:mashable.com,format:json,Time:2015-07-

ruby-on-rails - 摩卡 : How to add expectation of a method when there are multiple invocations with different parameters

我有一个RailsControllerAction要测试。在那个Action中,一个方法User.can?使用不同的参数多次调用。在其中一个测试用例中,我想确保User.can?('withdraw')被调用。但我不关心User.can的调用?与其他参数。defaction_to_be_tested...@user.can?('withdraw')...@user.can?('deposit')...end我在测试中尝试了以下:User.any_instance.expects(:can?).with('withdraw').at_least_once.returns(true)但是测

ruby-on-rails - rails : Opposite of Hash#to_param

如果我将哈希值转换为查询字符串,我该如何将其再次转换回来?{:filters=>{:colour=>['Red','Blue'],:size=>'Medium'}}.to_param=>"filters[colour][]=Red&filters[colour][]=Blue&filters[size]=Medium"Rails似乎在填充params散列时自动执行此操作,但是否可以直接调用此方法?谢谢。 最佳答案 您正在寻找Rack::Utils.parse_nested_query(query),它将把它转换回Hash。您可以使用

ruby-on-rails - 没有路由匹配 { :controller= >"stocks", :action= >"create"} RSpec Rails 3

我不明白为什么我在运行RSpec时收到此错误消息:Failure/Error:post:createActionController::RoutingError:Noroutematches{:controller=>"stocks",:action=>"create"}controllerstocks存在,actioncreate存在,它应该使用的路由是这样的:match'stocks/:user_id'=>'stocks#create',:via=>:post,:as=>:query路由文件:FruthScreener::Application.routes.drawdoroot:

ruby-on-rails - ActiveModel - 查看 - Rails 中的 Controller 而不是 ActiveRecord?

我正在尝试对我的模型使用ActiveModel而不是ActiveRecord,因为我不希望我的模型与数据库有任何关系。下面是我的模型:classUserincludeActiveModel::Validationsvalidates:name,:presence=>truevalidates:email,:presence=>truevalidates:password,:presence=>true,:confirmation=>trueattr_accessor:name,:email,:password,:saltdefinitialize(attributes={})@name

ruby-on-rails - 在带有 HTTPParty 的 Controller 中解析 JSON

在我的Controller中,我有以下代码...response=HTTParty.get('https://graph.facebook.com/zuck')logger.debug(response.body.id)我收到一个NoMethodError/undefined方法`id'如果我这样做...logger.debug(response.body)它按预期输出...{"id":"4","name":"MarkZuckerberg","first_name":"Mark","last_name":"Zuckerberg","link":"http:\/\/www.faceboo

ruby 管道 : How do I tie the output of two subprocesses together?

在Ruby中是否有自动执行shell管道的方法?我正在尝试将以下shell代码转换为Ruby:a|b|c...>...但到目前为止我找到的唯一解决方案是自己进行缓冲区管理(经过简化,未经测试,希望它能理解我的意思):a=IO.popen('a')b=IO.popen('b','w+')Thread.new(a,b){|in,out|out.write(in.readpartial(4096))untilin.eof?out.close_write}#dealwithb.read...我想我正在寻找的是一种告诉popen使用现有流而不是创建新流的方法?或者,将a的输出连接到b的输入的IO

ruby - 如何打印 unicode 字符 U-1F4A9 'pile of poo' 表情符号

我正在尝试在Ruby中打印一个unicode字符,特别是一堆便便。它的unicode值为U-1F4A9。但是当我尝试将“\u1F4A9”打印到输出或文件时,我什么也没看到。我是否需要打印到特定类型的文件才能看到一堆便便?如果是这样,什么类型的文件?有没有办法将其打印到公共(public)输出?(我正在使用Rubymine) 最佳答案 超过四个十六进制数字的Unicode代码点必须用花括号括起来:puts"\u{1f4a9}"#=>?这方面的文档很少,所以不要因为没有弄明白而难过。大括号语法的一个好处是您可以嵌入多个由空格分隔的代码点

ruby-on-rails - rails in_groups 和 in_groups_of 有什么区别?

这两种方法听起来应该做同样的事情,但它们似乎并不是彼此的别名。in_groups和in_groups_of有什么区别?Array#in_groupsArray#in_groups_of 最佳答案 文档很清楚。in_groups(数字,fill_with=nil)Splitsoriteratesoverthearrayinnumberofgroups,paddinganyremainingslotswithfill_withunlessitisfalse.in_groups_of(数字,fill_with=nil)Splitsorit