草庐IT

current_thread

全部标签

ruby-on-rails - 注销前更新 current_user 时收到 "Attempted to update a stale object: User"异常

我在我的用户模型上启用了乐观锁定,以处理我代码库各个部分中可能发生的冲突。但是,我遇到了意外冲突,我不知道如何处理它,因为我不知道是什么原因造成的。我正在使用Devisegem进行身份验证,并且正在使用before_logout方法来重置安全token...classSessionsController:createbefore_filter:before_logout,:only=>:destroydefafter_login#logictosetthesecuritytokenenddefbefore_logoutcurrent_user.update(security_token

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-on-rails - Mac OS X 山狮 "Rails is not currently installed on this system."

我正在全新安装OSXMountainLion。我通过以下方式安装了Rails:sudogeminstallrails一切似乎都安装正确,但是当我键入rails命令(railss、rails-v等)时,我收到此错误:Railsisnotcurrentlyinstalledonthissystem.Togetthelatestversion,simplytype:$sudogeminstallrailsYoucanthenrerunyour"rails"command.'whichrails'的结果是/usr/bin/rails我认为这是一个路径问题,也许是,但我可以看到/usr/bin是

Ruby 并发 : non-blocking I/O vs threads

我正在研究Ruby(1.9.3-p0)中的并发性,并创建了一个非常简单的I/O密集型代理任务。首先,我尝试了非阻塞方法:require'rack'require'rack/fiber_pool'require'em-http'require'em-synchrony'require'em-synchrony/em-http'proxy=lambda{|*|result=EM::Synchrony.syncEventMachine::HttpRequest.new('http://google.com').get[200,{},[result.response]]}useRack::Fi

ruby - 我想覆盖设计 gem 的 authenticate_user 和 current_user 方法

我想覆盖authenticate_user!和我的应用程序Controller中设计gem的current_user方法你能帮我解决这个问题吗谢谢 最佳答案 你可以像猴子一样修补它:moduleDevisemoduleControllersmoduleHelpersdefauthenticate_user!#dosomestuffendendendend但我会问最终目标是什么,因为Devise已经内置了一些可定制性,覆盖这些方法让我想知道“为什么要使用Devise?” 关于ruby-我想

ruby - Rails current_path helper ?

我正在开发具有以下路由条件的Rails3.2应用程序:scope"(:locale)",locale:/de|en/doresources:categories,only:[:index,:show]get"newest/index",as::newestend我有一个包含以下内容的Controller:classLocaleController我在模板中将它与类似的东西一起使用:=link_toset_locale_path(locale::de,return_to:current_path(locale::de))do=image_tag'de.png',style:'vertic

ruby - 什么时候需要将参数传递给 `Thread.new` ?

在线程外部定义的局部变量似乎从内部可见,因此Thread.new的以下两种用法似乎是相同的:a=:fooThread.new{putsa}#=>:fooThread.new(a){|a|putsa}#=>:foodocument举个例子:arr=[]a,b,c=1,2,3Thread.new(a,b,c){|d,e,f|arr[1,2,3]但由于a、b、c在创建的线程内部是可见的,所以这也应该与:arr=[]a,b,c=1,2,3Thread.new{d,e,f=a,b,c;arr[1,2,3]有区别吗?什么时候需要将局部变量作为参数传递给Thread.new?

ruby - Thread.join 阻塞主线程

调用Thread.join会阻塞当前(主)线程。然而,当主线程退出时,不调用join会导致所有生成的线程被杀死。如何在不阻塞主线程的情况下在Ruby中生成持久性子线程?这是连接的典型用法。foriin1..100doputs"Creatingthread#{i}"t=Thread.new(i)do|j|sleep1puts"Thread#{j}done"endt.joinendputs"#{Thread.list.size}threads"这给出了Creatingthread1Thread1doneCreatingthread2Thread2done...1threads但是我正在寻找

system.threading.Timer每天尝试同时制作计时器

我在控制台服务应用中使用system.threading.timer,并尝试每天同时制作计时器。最初,如果我在时间之前启动该应用程序,我会很好。就像我的时间是10:05,我从10:00启动该应用程序,我们很好。但是,如果我从10:06开始,我就不知道如何告诉时间台下24小时。谢谢你的帮助!publicvoidSetUpTimer(TimeSpanalertTime){DateTimecurrent=DateTime.Now;TimeSpantimeToGo=alertTime-current.TimeOfDay;if(timeToGo{EventLog.WriteEntry("MhyApp",

ruby-on-rails - 如何在 rspec 功能测试中访问(设计)current_user?

在设计文档中,他们提供了有关在测试Controller时如何访问current_user的提示:https://github.com/plataformatec/devise/wiki/How-To:-Test-controllers-with-Rails-3-and-4-%28and-RSpec%29但是,在进行功能测试时呢?我正在尝试测试我的一个Controller的创建方法,并且在该Controller中使用了current_user变量。问题是devise中建议的宏使用了@request变量,并且对于功能规范来说它是nil。什么是解决方法?编辑:这是我目前的规范:feature