草庐IT

expiration_date

全部标签

ruby-on-rails - Rails 2.3.5 - ".find"函数不适用于 ( :condition = >"date") option

我想做的是查找过去60天内使用过的特定记录。我正在使用Oracle(9i),railsv:2.3.5,rubyv:1.8.7我定义日期间隔的代码是:date=(((Time.now-60.days).strftime("%d-%b-%y"))...(Time.now.strftime("%d-%b-%y")))下面是我如何使用它:conditions={}conditions[:start_date]=dateconditions[:account_no]=account_numberresults=MyModel.find(:all,:conditions=>conditions)要

ruby-on-rails - 尽管 expires_in 24.hours,Rails 缓存值丢失/为零

我将ruby​​2.3.3和Rails4.2.8与Puma(1个工作人员,5个线程)一起使用,在我的管理(即不重要)页面上,我想显示我的数据库中的一些统计信息(整数值)。有些请求需要很长时间才能执行,所以我决定缓存这些值并使用rake任务每天重写它们。Admin#indexControllerrequire'timeout'begintimeout(8)do@products_a=Rails.cache.fetch('products_a',:expires_in=>24.hours){Product.where(heavy_condition_a).size}@products_b=

ruby - gem date_validator 不工作 Ruby 1.9.3 Rails 3.2.1

我刚刚安装了这个gem:geminstall'date_validation'我可以看到它已正确安装,因为它在我使用时出现在列表中:gemlist但是当我尝试将字段表单的内容验证为日期时,出现此错误:ArgumentErrorinProductesController#newUnknownvalidator:'DateValidator'我使用这段代码来验证:validates:data_caducitat,:date=>{:after=>Proc.new{Time.now}}知道可能是什么问题吗?提前致谢。 最佳答案 Rails3

ruby-on-rails - Rails routing with date 并且有很多

我有以下设置:map.resources:articlesmap.resources:users,:has_many=>[:articles]这很好,因为我可以执行/users/2/articles来获取给定用户的文章列表。我还有一个路线设置要做:map.connect'articles/month/:month/:year',:controller=>'articles',:action=>'index'这适用于查找给定月份和给定年份的所有文章。我现在想做的是显示给定用户在给定月份和年份的文章。也许是这样的url:/users/2/articles/month/4/2009有没有一种

ruby-on-rails - Rails Date#strptime 在 200 年之前错误地解析日期

为什么Rails的Date#strptime将“13/08”解析为200年之前的8月15日或8月14日?Date.strptime('13/08/99','%d/%m/%Y')#=>Thu,15Aug0099Date.strptime('13/08/100','%d/%m/%Y')#=>Fri,14Aug0100Date.strptime('13/08/199','%d/%m/%Y')#=>Tue,14Aug0199Date.strptime('13/08/200','%d/%m/%Y')#=>Wed,13Aug0200 最佳答案

ruby-on-rails - 参数转换的禅宗方式[:date] to Date?

将params[:date]字段转换为Date对象的最优雅的方法是什么?"date"=>{"day"=>"13","year"=>"2012","month"=>"4"}目前,我在controller中有如下代码:@date=Date.currentifparams[:date]yy=mm=dd=0yy=params[:date][:year].to_iifparams[:date][:year]mm=params[:date][:month].to_iifparams[:date][:month]dd=params[:date][:day].to_iifparams[:date][:

ruby-on-rails - 为什么 Date.tomorrow > Time.now 在 Ruby on Rails 中返回 false?

查看RoRpry控制台结果:[1]pry(main)>Date.tomorrow>Time.now=>false[2]pry(main)>Date.tomorrow.to_time>Time.now=>true[3]pry(main)>Date.tomorrow=>Tue,07Oct2014[4]pry(main)>Time.now=>2014-10-0622:52:40-0400添加了时间戳结果,让您知道粗略的值。 最佳答案 因为Date.tomorrow是明天而Time.nowUTC也是明天。您会注意到您在10:52pm执行此操

引用 Date 时出现 Ruby NameError

我使用以下代码得到“未初始化的常量日期(NameError)”:classTestattr_accessor:reqsdefinitialize()@reqs=[]endendclassTestBuilderdeftest(&block)@current=Test.newblock.call@currentenddefolder_than_days(age)@current.reqs"Mon,5Apr201003:17:46-0400"})阅读这个问题的答案后添加了双冒号:Uninitializedconstant...NameError因为ruby​​试图在TestBuilder中查

ruby - : Date. 如何解析 ("123 456 789") == 2019 年 5 月 3 日星期五?

标题几乎说明了一切。我正在尝试从CSV导入中评估日期的有效性,但如果有人为出生日期选择电话号码列,日期解析仍然会通过 最佳答案 Howis:Date.parse(“123456789”)==Fri,03May2019?Date._parse(带下划线)返回原始数据:Date._parse('123456789')#=>{:yday=>123}Ruby将123视为一年中的第123天,即5月3日。 关于ruby-:Date.如何解析("123456789")==2019年5月3日星期五?,我

ruby-on-rails - rails : to_date with a month/day/year format

我有一个简单的问题。我有一个带有created_at的实例变量。我如何将其转换为Month,day,year~September,13,1987当我尝试=@example.created_at在我看来它给了我1987-09-13奇怪的是,当我在控制台中执行此方法时,我得到了Sun,13Sep1987如何将我的变量转换为月、日、年?为什么它在控制台中返回不同的东西? 最佳答案 您可以通过指定格式来更改日期的显示方式,例如@example.created_at.strftime("%B,%d,%Y")#=>"September,20,2