草庐IT

preg-match-all

全部标签

ruby-on-rails - 在 Rails 3 中使用 current_page 时为 "No routes matches"

有没有人遇到过使用current_page时路由神秘地变得无法检测到?在Rails3中?即使使用包含路由、View和Controller的完全生成的脚手架,我也会收到“无路由匹配”错误。代码如下:ifcurrent_page?(:controller=>'users',:action=>"show")如果我向routes.rb添加一个“匹配”命令,它工作正常,但如果资源已经创建,为什么我需要这样做呢?我错过了什么? 最佳答案 如果你只是想测试当前的Controller,你可以这样做:ifparams[:controller]=='u

ruby - “Stack level too deep” 运行 rake 数据库 :create:all

当我运行rakedb:create:all时,我收到以下消息:/Users/junior/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/version.rb:4:warning:alreadyinitializedconstantMAJOR/Users/junior/.rvm/gems/ruby-1.9.2-p290@global/gems/rake-0.9.2/lib/rake/version.rb:5:warning:alreadyinitializedconstantMINOR/Users/junior/.rv

ruby - 如何在 rspec 之前访问元数据(:all)?

我希望能够在before(:all)方法期间显示测试组名称(和祖先):describe"Myawesomeapp"dobefore(:all)doputsrunning_example_group.metadata[:full_description]#这个想法是会产生输出:MyawesomeappMyawesomeappawesomewidget此数据在“it”子句中可用,但我无法在before(:all)中弄清楚。它不可用吗?我是不是犯了一个愚蠢的错误? 最佳答案 在before(:all)block中,没有“运行示例”,但您仍

ruby-on-rails - 验证失败 : Upload file has an extension that does not match its contents

我正在使用回形针gem上传文件。我的回形针gem版本是paperclip-4.1.1。上传文件时抛出Validationfailed:Uploadfilehasanextensionthatdoesnotmatchitscontents.我正在尝试上传xlsx文件。而且我已经在模型content_type中提到了这一点。validates_attachment_content_type:upload_file,:content_type=>%w(application/mswordapplication/vnd.ms-officeapplication/vnd.ms-excelappl

ruby-on-rails - rails : Return only objects where all associations meet a condition

设置:Rails3.2.18、Postgres我有两个对象,例如,将它们称为Author和Article,具有以下设置:classAuthorhas_many:articles...endclassArticlebelongs_to:authorclass我正在尝试查找所有Author记录,其中所有相关的Article记录都是在一年前发布的。这段代码:Author.joins(:article).merge(Article.published_over_one_year_ago)...返回Author对象,其中至少一个关联的Article是在一年多以前发表的,但我只需要作者记录,其中所

ruby-on-rails - 我将如何 destroy_all 或 delete_all 记录,除了 ruby​​ on rails 中的一条记录?

我在我的网站上为我的用户消息线程功能使用“acts_as_tree”插件。我有一种方法可以删除选定的消息。这些消息实际上并没有被删除。它们的sender_status或recipient_status列设置为1,具体取决于邮件的发件人或收件人是哪个用户。无论如何,如果两个用户都将这些状态设置为1,那么最后一行确保消息行已完全从数据库中移出。现在这很好,只要它不是被删除的父消息。如果删除父消息,则将无法再访问未被选择删除的子消息。方法如下:defdelete_all_users_selected_messages(message_ids,user_id,parent_id)Message

ruby-on-rails - ruby 的 "any?"和 "all?"方法在空数组和哈希上的行为

首先,我在有关这些方法的文档中找到了两篇有用的文章:http://www.ruby-doc.org/core-1.9.3/Enumerable.htmlhttp://www.globalnerdy.com/2008/01/29/enumerating-rubys-enumerable-module-part-1-all-and-any/all?:Passeseachelementofthecollectiontothegivenblock.Themethodreturnstrueiftheblockneverreturnsfalseornil.any?:Passeseachelemen

ruby-on-rails - 如何摆脱 Spring 警告 : Running `gem pristine --all` ?

我正在使用Springapplicationpreloader并刚刚升级到v0.9.0。现在我收到以下警告:Warning:Runninggempristine--alltoregenerateyourinstalledgemspecswillimprovethestartupperformanceofSpring.我尝试运行该命令,但它无法安装我的一些gem,这可能与我最近升级到OSXMavericks有关。我如何摆脱这个警告? 最佳答案 这是因为以前版本的ruby​​gems会在查询时加载所有的gemspecs。开始时速度很慢,

ruby-on-rails - 错误 "' Validate_default_type !': An option' s default must match its type (ArgumentError)"when running Ruby on Rails generate on Windows

我正在关注thistutorial并且刚刚开始。我已经使用geminstallrails安装了RubyonRails,并使用railsnewblog创建了一个博客。教程现在说我需要运行railsgeneratecontrollerWelcomeindex,但是当我这样做时,我得到了这个错误:C:/Ruby22/lib/ruby/gems/2.2.0/gems/thor-0.19.2/lib/thor/parser/option.rb:130:in`validate_default_type!':Anoption'sdefaultmustmatchitstype.(ArgumentErr

ruby - Regexp.last_match 线程安全吗?

这是我正在查看的代码:defmethod_missing(id,*args)returnself.find(Regexp.last_match(1),args[0])ifid.id2name=~/find_by_(.+)/raiseNoMethodErrorend如果我有多个线程调用Regexp.last_match会怎样?如果我有多个线程使用method_missing方法调用对象会怎样? 最佳答案 Ruby1.9.2平台文档声明调用Regexp.last_match等同于读取特殊的$~全局变量。摘自“TheRubyProgram