草庐IT

DAY_OF_WEEK_IN_MONTH

全部标签

ruby - 应该 validate_format_of 。 not_with 在框架中有问题(或者在我的理解中)

我将以下代码放入RSpec测试中:it{shouldvalidate_format_of(:email).not_with('test@test')}并设置实际的类:validates:email,:presence=>true,:format=>/\b[A-Z0-9._%-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}\b/i当我运行测试时,我得到:失败:1)用户失败/错误:它{应该validate_format_of(:email).not_with('test@test')}当电子邮件设置为“test@test”时,预期错误包括“can'tbeblank”,得到错误

ruby - 欧拉计划 1 :Find the sum of all the multiples of 3 or 5 below 1000

我正在尝试使用ProjectEuler中的Ruby解决数学问题。Here是我尝试的第一个:Ifwelistallthenaturalnumbersbelow10thataremultiplesof3or5,weget3,5,6and9.Thesumofthesemultiplesis23.Findthesumofallthemultiplesof3or5below1000.请帮助我改进我的代码。total=0(0...1000).eachdo|i|total+=iif(i%3==0||i%5==0)endputstotal 最佳答案

ruby-on-rails - Michael Hartl Rails Tutorial 第 7 章错误 Action not found in UsersController

我目前正在学习MichaelHartl的Rails教程,我已经顺利地达到了7.22。然而,我对测试的输出感到难过:Failures:1)UserPagessignupwithinvalidinformationshouldnotcreateauserFailure/Error:expect{click_buttonsubmit}.not_tochange(User,:count)AbstractController::ActionNotFound:Theaction'create'couldnotbefoundforUsersController#(eval):2:in`click_b

ruby-on-rails - 我得到 rvm : command not found after installation of rvm

我知道上面的问题是很常见的问题。我已经阅读了关于这个主题的多篇文章。但是我没有得到任何解决方案。我已经在本地安装了rvm。我们已经有了安装文件。所以进入文件夹并运行安装命令。$./install然后我检查了Users主文件夹中的./rvm文件夹$cd~/.rvm文件夹存在。至此安装成功。现在我在命令行输入rvm$rvm我正在低于异常$rvm-sh:rvm:commandnotfound在阅读了stackoverflow中有关此问题的多篇文章后,我了解到我必须在.bash_profile中添加以下行,因为我使用的是MacOSX10.7.3[[-s"$HOME/.rvm/scripts/r

ruby-on-rails - rails : Detecting user agent works in development but not production?

我正在尝试在我的应用程序中检测黑莓用户代理,这在我的开发版本中运行良好。但是当我在生产环境中重新部署该应用程序时,没有任何反应。application_helper.rbdefblackberry_user_agent?request.env["HTTP_USER_AGENT"]&&request.env["HTTP_USER_AGENT"][/(Blackberry)/]end应用程序.html.erbUsingaBlackberry?Usethemobileoptimizedversion.我已经尝试使用raketmp:cache:clear清除缓存并重新启动mongrel几次。显

ruby-on-rails - rails : Using CanCan to define multiple roles depending on instances of single Model?

我目前一直在研究如何根据我们想要的每个条件来分离CanCan的角色。在我们的应用程序中,有很多类别(例如数学、英语、历史等),每个类别中都有很多类(class)。每个用户可以在每个类别中扮演许多不同的角色。例如,约翰可以是数学的“读者”,这意味着他可以阅读所有数学类(class)。约翰也可以是英语的“作家”,这意味着他可以阅读所有英语类(class),在类别英语中创建类(class),并仅编辑/删除他创建的英语类(class)。如果这些是John仅有的角色,他将无法在导航栏中看到类别历史记录,并且将被拒绝访问历史记录中的类(class)。这些是关系的建立方式:classUser在mod

ruby-on-rails - :autosave property of has_many associations broken in Rails 2. 3.4?

在我将此作为错误发布给Rails团队之前,我想看看我是否做错了可能导致此行为的事情。具体来说,has_many关联的:autosave属性似乎没有按照文档工作。作为引用,这里是最新的API文档:http://api.rubyonrails.org/classes/Acti...ation.html查看“一对多示例”部分。我已经在测试应用程序中完全复制了代码,但它对我不起作用。具体来说,更新父对象,但不更新子对象。我的架构如下:create_table:postsdo|t|t.string:titlet.timestampsendcreate_table:commentsdo|t|t.t

ruby - MRI 内部结构 : detailed explanation of rb_id2str

在MRI中,似乎rb_id2str()当您调用Symbol#to_s时负责完成所有工作.我惊讶地发现这是一个极其神秘的函数,而我认为这是一个相当直接的操作。我正在寻找有关此功能的详细说明。作为引用,这里是1.9.3中源代码的链接:http://rxr.whitequark.org/mri/source/parse.y?v=1.9.3-p195#9950一些具体问题:什么是四大ifblock在做什么?if(idif(idif(st_lookup(global_symbols.id_str,id,&data))if(is_attrset_id(id))如果能大致了解if语句中每个代码块的作

ruby - gem 更新——系统返回 "no implicit conversion of nil into String"

运行gemupdate--system不断返回错误#gemupdate--systemUpdatingrubygems-updateERROR:Whileexecutinggem...(TypeError)noimplicitconversionofnilintoString如何解决?详细:http://pastebin.com/2uBYEMTi 最佳答案 这可能是由于不兼容的gem版本(也许是一个正在做Monkey补丁的gem?)。您可以尝试更新单个gem吗? 关于ruby-gem更新

Ruby,从 Date.day_fraction_to_time 获取小时、秒和时间

我找到了这个方法here.start=DateTime.nowsleep15stop=DateTime.now#minutesputs((stop-start)*24*60).to_ihours,minutes,seconds,frac=Date.day_fraction_to_time(stop-start)我有以下错误:`':privatemethod`day_fraction_to_time'calledforDate:Class(NoMethodError)我检查了/usr/lib/ruby/1.9.1/date.rb并找到了它:defday_fraction_to_time(