我想创建一个查询,它将返回所有“现在”之前有一个开始时间的警报和“现在”之后的结束时间,我只关心它的一天中的哪个时间,而不是它的日期是
我原以为这会起作用
Alert.find(:all, :conditions => [" ? between ? AND ?", Time.now, :start, :end])
然而,它并不是因为此查询涉及日历日期,而不仅仅是时间。
我发现“.to_s(:time)”但是当我添加时我收到错误。
Alert.find(:all, :conditions => [" ? between ? AND ?", Time.now.to_s(:time), :start.to_s(:time), :end.to_s(:time)])
Alert.find(:all, :conditions => [" ? between ? AND ?", Time.now.to_s(:time), :start.to_s(:time), :end.to_s(:time)])
ArgumentError: wrong number of arguments(1 for 0)
from (irb):48:in `to_s'
from (irb):48
from /home/chris/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/commands/console.rb:47:in `start'
from /home/chris/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/commands/console.rb:8:in `start'
from /home/chris/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.2.3/lib/rails/commands.rb:41:in `'
from script/rails:6:in `require'
from script/rails:6:in `'
如何根据现在处于警报的开始和结束时间之间找到所有现在处于活动状态的警报,而不管开始和结束时间的日历日期是什么?我目前没有考虑时区,但将来会考虑。
答案 0 :(得分:1)
此问题表示使用sqlite时ActiveRecord中的错误。解决方法是切换到mysql。更多信息:https://github.com/rails/rails/issues/6247#issuecomment-5679856