草庐IT

ios - 标签栏 Controller 中多个标签的一个导航 Controller

全部标签

ruby - 编写一个 ruby​​ 命令行应用程序;最好的方法是做到这一点?

我有一个正在开发的命令行Ruby应用程序,我想允许它的用户提供将在部分过程中作为过滤器运行的代码。基本上,应用程序是这样做的:读入一些数据如果指定了过滤器,则使用它来过滤数据处理数据我希望过滤过程(第2步)尽可能灵活。我的想法是,用户可以提供一个Ruby文件,该文件设置一个已知常量以指向实现我定义的接口(interface)的对象,例如:#user'sfilterclassMyFilterdefdo_filter(array_to_filter)filtered_array=Array.new#domyfilteringonarray_to_filterfiltered_arrayen

ruby-on-rails - Rails Postgresql 多个模式和相同的表名

我在两个不同的模式中有两个表,例如案例和事件。在每个模式中我都有基本表events.basiccases.basic这个表有关系:events.basic有一个cases.basic(cases.basic有多个events.basic)我的尝试失败了:文件cases_basic.rbclassCasesBasic'EventsBasic',:foreign_key=>'case_id'end文件events_basic.rbclassEventsBasic'CasesBasic',:foreign_key=>'case_id'end环境:Ruby1.9.3、Rails3.1.3、ge

ruby-on-rails - Rails Controller 操作是否隐式定义事务绑定(bind)?

给定以下代码:defcreate@something=Something.new(params[:something])thing=@something.thing#anothermodel#modificationofattributesonboth'something'and'thing'omitted#doIneedtowrapitinsideatransactionblock?@something.savething.saveendcreate方法是隐式包装在ActiveRecord事务中,还是需要将其包装到事务block中?如果我确实需要包装它,这是最好的方法吗?

ruby-on-rails - rails : Pass Parameters to New Controller during 'redirect_to'

我正在使用RyanBates的RailsCastonWickedWizardForms创建一个多步骤表单。我没有定义current_user方法(不使用身份验证gem)-因此,我试图在redirect_to期间传递user.id参数-不幸的是,我似乎无法让它工作。任何帮助表示赞赏!我的用户Controller创建方法defcreate@user=User.new(params[:user])respond_todo|format|if@user.saveformat.html{redirect_tocontroller:'user_steps',id:'user.id'}#format

ruby - 在数组中找到 block 返回 true 的第一个元素并返回 block 的返回值

我需要遍历数组并将提供的block应用于每个元素,并返回block返回的第一个真值,这意味着我需要在获得真值后立即停止。下面是我的代码。我是ruby新手,我不确定这段代码是否是在重新发明轮子。也许已经有一个或多个库方法可以做到这一点?还是可以简化此代码?RS={:x=>%w(\d+a\d+bb\d+ccc\d+).map{|x|/^#{x}$/},:y=>%w(\w+1\w+22\w+333\w+).map{|x|/^#{x}$/}}.freezedeffinds,tr=RS[s]ifrr.eachdo|p|m=p.matchtreturnmifmendnilendendpfind:x

ruby-on-rails - 具有多个参数的 RSpec 和自定义匹配器

我正在尝试使用RSpec为我在RoR中的测试创建自定义匹配器。define:be_accessibledo|attributes|attributes=attributes.is_a?(Array)?attributes:[attributes]attributes.eachdo|attribute|matchdo|response|response.class.accessible_attributes.include?(attribute)enddescription{"#{attribute}shouldbeaccessible"}failure_message_for_shou

ruby-on-rails - 为什么 Controller 操作应该调用一个模型方法而不是初始查找或新方法?

我的模型中的函数几乎包含所有“共享”语句。问题是,当我需要在我的Controller中使用多个功能时,出现以下错误:ControlleractionshouldcallonemodelmethodotherthananinitialfindornewIDE会更深入地解释:Thisinspectionwarnsifacontrolleractioncontainsmorethanonemodelmethodcall,aftertheinitial.findor.new.It’srecommendedthatyouimplementallbusinesslogicinsidethemode

ruby-on-rails - 如何 'rake spec' 一个目录,例如楷模?

我可以rakespec并运行所有规范。但是尝试为一个目录运行规范,如rakespec/models/orrakespec/models/*.rb不提供任何输出或错误。一个选项是我可以做rspecspec/models/*.rb或rspecspec/models/但我想知道我是否可以留在Rake。 最佳答案 尝试使用rakespec:models而不是rakespec/models。运行rake-T|grepspec查看所有可用的rakespec任务。更新:通过rakespec运行规范可能比通过rspecspec运行它们慢,rspec

ruby-on-rails - 在调用 Rake 任务时设置多个环境变量

我可以像这样调用一个Rake任务并设置一个环境变量:$ONE=1raketemp:both但是如何设置两个环境变量呢?这行不通:$ONE=1TWO=2raketemp:both这行得通,但读起来很困惑:$ONE=1raketemp:bothTWO=2如何在调用rake之前传递多个环境? 最佳答案 同意@Ernest;它应该工作。这是一个示例...示例rake任务以回显变量:task:echo_envdoputs"VAR1:#{ENV['VAR1']}"puts"VAR2:#{ENV['VAR2']}"end执行任务:VAR1=fir

ruby-on-rails - RSpec 中单个设置的多个断言

我想优化一些较慢的规范。此类规范的示例如下所示:require'rspec'classHeavyComputationdefcompute_resultsleep1#somethingcomputeheavyhere"verybigstring"endenddescribeHeavyComputation,'preferredstyle,butslow'dosubject{described_class.new.compute_result}it{shouldinclude'big'}it{shouldmatch'string'}it{shouldmatch/very/}#+50oth