rails 4 中用于从 #scope 或 #default_scope 块返回哈希的弃用警告



所以我有这样用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)) }

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

我不知道

这是否是标准代码,但通过这种方式我已经做到了,

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

如果我错了,请纠正我。

谢谢

最新更新