草庐IT

update_current_stock_price

全部标签

ruby-on-rails - 在 after_update 回调中获取更改的属性

我正在尝试进行有条件的after_update,我有以下内容:after_updatedo|participant|Rails.logger.info"#{self.previous_changes}changed."ifself.previous_changes.include?(:current_distance)#Domystuff...endend记录器打印空哈希:{}如何检查哪个属性已更改?我正在使用:participant.update_attribute(:current_distance,distance)来更新属性。 最佳答案

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 - Rails 4 - 想让 Rails 将我的本地时区用于 created_at 和 updated_at

是否真的有办法让Rails使用我服务器上设置的当前时区使用created_at和update_at添加/更新行?我见过许多StackOverflow解决方案,其中人们说明了如何在具有选定时区的RailsView上显示它。我还发现其他StackOverflow解决方案指出它应该从我的服务器获取时区并更新created_at和updated_at。至少对于我正在运行的MacMini服务器而言,情况并非如此。我把它设置为我本地的时区。我还在config/application.rb中设置了config.time_zone='CentralTime(US&Canada)'。我希望能够查看pgA

ruby - update(other_hash) 和 merge(other_hash) 的区别

更新代码:irb(main):001:0>h1={"a"=>100,"b"=>200}=>{"a"=>100,"b"=>200}irb(main):002:0>h2={"b"=>254,"c"=>300}=>{"b"=>254,"c"=>300}irb(main):003:0>h1.update(h2)=>{"a"=>100,"b"=>254,"c"=>300}合并代码:irb(main):001:0>h1={"a"=>100,"b"=>200}=>{"a"=>100,"b"=>200}irb(main):002:0>h2={"b"=>254,"c"=>300}=>{"b"=>254,

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 - 我想覆盖设计 gem 的 authenticate_user 和 current_user 方法

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

ruby-on-rails - 没有路由匹配 { :controller= >"stocks", :action= >"create"} RSpec Rails 3

我不明白为什么我在运行RSpec时收到此错误消息:Failure/Error:post:createActionController::RoutingError:Noroutematches{:controller=>"stocks",:action=>"create"}controllerstocks存在,actioncreate存在,它应该使用的路由是这样的:match'stocks/:user_id'=>'stocks#create',:via=>:post,:as=>:query路由文件:FruthScreener::Application.routes.drawdoroot:

ruby-on-rails - 在 Rails 3 中使用 update_columns?

在Rails3中有更短的方法吗?user.update_column(:attribute1,value1)user.update_column(:attribute2,value2)user.update_column(:attribute3,value3)user.update_column(:attribute4,value4)我试过update_columns但它只在Rails4中可用。感谢您的帮助。 最佳答案 这是Rails3.x的解决方法:User.where(id:user.id).update_all(attribu

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-on-rails - 使用#update_all 更新时间戳

当我有要更新其属性的ID列表时,数据库中的updated_at字段似乎没有改变,这就是我的意思:ids=[2,4,51,124,33]MyObj.where(:id=>ids).update_all(:closed=>true)执行此更新后,updated_at字段不会更改。但是,当我使用railsc进入rails控制台并执行此操作时:obj=MyObj.find(2)obj.closed=false;obj.save!在此语句之后updated_at字段更改值。为什么是这样?当发生这种情况时,我正在监听更新并执行整个应用程序流程时,我依赖于我的应用程序中的这个updated_at字段