草庐IT

nth-of-type

全部标签

ruby-on-rails - rails 2.3.8, ruby 1.8.6 : Getting a visual call tree/graph of what methods call what?

我有一个中等复杂度的Rails应用程序。主Controller(执行应用程序所要做的事情的Controller)只有一个操作方法。(它不是标准的RESTful应用程序;它充当中介,并且对其调用方式有外部限制。)但是,它确实有很多方法和一些过滤器,以及一个不断增长的测试套件。随着时间的推移,结构发生了很大变化,我不再相信为之前编写的测试设置的某些Mocha期望仍然合适。有多个人在开发该应用程序,因此我正在构建一本用于编写功能测试的指南。“当你想在有/没有[那些]副作用的情况下进行测试时,使用[这些]期望和断言”等等。调用树/图在编写此类文档时非常有用。除了过滤器之外,这些甚至可以静态地从

ruby-on-rails - 类型错误 : wrong argument type String (expected Module)

我有以下代码:classProfileLookup基本上包含大量查找数据,按类别拆分。目的是为数据库中的每个类别创建一个方法。通过Rails控制台,此代码按预期工作:ruby-1.9.3@hub:002>ProfileLookup.available_gendersProfileLookupLoad(0.6ms)SELECT"profile_lookups".*FROM"profile_lookups"WHERE"profile_lookups"."category"='gender'ORDERBYvalue=>["Female","Male"]但是,我的规范不合格。以下规范:requ

ruby - 调用 instance_eval(&lambda) 传递当前上下文时出现错误 'wrong number of arguments'

要清楚-此代码运行完美-codewithproc但如果我将Proc.new更改为lambda,则会出现错误ArgumentError:wrongnumberofarguments(1for0)这可能是因为instance_eval想要将self作为参数传递,而lambda将其视为一种方法并且不接受未知参数?有两个例子-第一个是工作:classRuledefget_ruleProc.new{putsname}endendclassPersonattr_accessor:namedefinit_rule@name="ruby"instance_eval(&Rule.new.get_rule

ruby - 为什么 inspect for the subclasses of built-in classes 中没有列出实例变量?

当我对内置类进行子类化时,为什么inspect中的行为会发生变化。但是当我子类化一个自定义的时没有看到。classMainErrorendclassAnotherTestErrort=TestError.newputst.inspect#output:# 最佳答案 因为很多(大多数?全部?)内置类是用C语言编写的,并且覆盖#inspect。例如,Exception(StandardError的父类(superclass))定义#inspect如下:exc_inspect(VALUEexc){VALUEstr,klass;klass=

ruby-on-rails - `allow_any_instance_of` 模拟不在范围内工作

我的mock只有在如下所示的beforeblock中时才有效。这只是我对我的问题的快速而肮脏的表述。从字面上看,当我将行从beforeblock移动到doesnotquack断言时,它停止模拟:(describe'Ducks',type::featuredobeforedo...allow_any_instance_of(Duck).toreceive(:quack).and_return('bark!')visitanimal_farm_pathendcontext'isanoddduck'it'doesnotquack'doexpect(Duck.new.quack).toeq('

ruby-on-rails - rails : render a collection of models using an specific html view

我有以下关于rails的简单问题。假设我有一个模型用户。在View中,如果我这样做:views/user/_user.html.erb中的文件View将为每个用户调用和打印。如何更改它以使用特定View?我需要这样的东西:User.all:template=>"user/_user_2ndview.html"%>有什么帮助吗?提前致谢 最佳答案 您可以使用collection选项:User.all,:partial=>"users/user2ndview",:as=>:user%>View必须放在views/users/_user2

ruby - 自定义 to_yaml 和 domain_type

我需要定义用于序列化/反序列化对象的自定义方法。我想做类似下面的事情。classPersondefto_yaml_type"!example.com,2010-11-30/Person"enddefto_yaml"stringrepresentingperson"enddeffrom_yaml(yaml)Person.load_from(yaml)endend声明序列化/反序列化的正确方法是什么? 最佳答案 好的,这就是我想出的classPersondefto_yaml_type"!example.com,2010-11-30/pe

ruby-on-rails - Ruby 类评估,validates_inclusion_of 与动态数据

如果我有如下的ActiveRecord模型classFooself.allowed_typesdefself.allowed_types#somecodethatreturnsanenumerableendend这不起作用,因为在评估验证时尚未定义allowed_types方法。我能想到的所有修复基本上都是围绕将方法定义移到验证之上,以便在需要时可用。我明白这可能更像是一个编码风格问题(我希望我的所有验证都在模型顶部,方法在底部)但我觉得应该有某种解决方案,可能涉及初始模型加载的惰性评估?我想做的事有可能吗?我应该只在验证之上定义方法,还是有更好的验证解决方案来实现我想要的。

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 - 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传递缓存计数解决了问题