从3.2升级到Rails4时,我收到了弃用警告
DEPRECATION WARNING:从#scope或#default_scope返回哈希值 块已弃用。请改为返回实际范围对象。 例如。范围:红色, - > {where(color:'red')}而不是范围:红色, - > {{conditions:{color:'red'}}}。 (范围定义于 /Users/newimac/RailsApp/bank/app/models/account.rb:101)。 (来自 pry at(pry):18)
运行此查询时
Account.need_processing(current)
并且
Account.need_processing(@current).should be_empty
我在Rails 3.2中将scope
定义为:
scope :need_processing, lambda {|cutoff| {:conditions => ["state = 'active' and processed_through < ?", cutoff.ago(1.day)]}}
升级到Rails 4.0.4之后。我已将scope
定义为
scope :need_processing, -> (cutoff) { where(state: active, processed_through: cutoff.ago(1.day)) }
在Rails 3.2和Rails 4.0中的两个查询之间检查processed_through
。
答案 0 :(得分:1)
scope :need_processing, ->(cutoff) {where("state = 'active' and processed_through < ?", cutoff.ago(1.day))}