2015-04-04 75 views
1

我使用了一个名为范围,试图找到记录由1个月前,这里是我的代码有:查找记录由1个月前

scope :six, -> {:conditions["records.created_at > ?", 1.month.ago]} 

和呼叫:

@sixmonths = human.human_logins.six 

虽然我似乎得到以下错误:

`can't convert ActiveSupport::TimeWithZone into Intege`r 

这发生在范围行上。

我是新来的范围,所以不知道我应该怎么做,任何想法都会很棒。

回答

2

我不熟悉:conditions方法,但是语法:conditions[]和异常表明它试图将表达式评估为Array。

如果只想创建正是1个月前的记录,使用以下命令:

scope :six, -> { where(created_at: 1.month.ago) } 

如果你想记录创建比一个月前更(其中您的查询语法建议),用途:

scope :six, -> { where("created_at > ?", 1.month.ago) }