【问题标题】:Deprecation warning in rails 4 for returning a hash from a #scope or #default_scope blockrails 4 中的弃用警告,用于从 #scope 或 #default_scope 块返回哈希
【发布时间】:2013-11-17 08:20:56
【问题描述】:

所以我在Rails 3.2.13 中编写了这样的代码,我将在Rails 4 中进行更改。

scope :between, lambda {|start_time, end_time|
{:conditions => ["? < starts_at < ?", Event.format_date(start_time), Event.format_date(end_time)] }}

我试过这样但没有成功..

scope :between, ->(starts_at, ends_at) { where(:starts_at => Event.format_date(starts_at), :ends_at => Event.format_date(ends_at)) }

可能是我错过了什么。请帮忙。 提前致谢。

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4


    【解决方案1】:

    我不知道这是否是标准代码,但我已经这样做了,

    scope :between, lambda { |starts_at, ends_at| where("? < starts_at < ?", Event.format_date(starts_at), Event.format_date(ends_at)) }
    

    如果我错了,请纠正我。

    谢谢

    【讨论】:

      猜你喜欢
      • 2014-04-22
      • 1970-01-01
      • 1970-01-01
      • 2016-03-07
      • 1970-01-01
      • 2017-03-01
      • 2013-08-19
      • 1970-01-01
      相关资源
      最近更新 更多