Reputation: 257
I'm using a named scope to try and find records made 1 month ago, here's the code I have:
scope :six, -> {:conditions["records.created_at > ?", 1.month.ago]}
And the call:
@sixmonths = human.human_logins.six
Though I seem to be getting the following error:
`can't convert ActiveSupport::TimeWithZone into Intege`r
This is occurring on the scope line.
I'm new to scopes so not sure how I should go about this, any ideas would be awesome.
Upvotes: 1
Views: 1630
Reputation: 1599
I am not familiar with :conditions
method, but the syntax, :conditions[]
and the exception suggests that it is trying to evaluate the expression as an Array.
If you want only records created exactly 1 month ago, use the following:
scope :six, -> { where(created_at: 1.month.ago) }
If you want records created more than a month ago (which your query syntax suggests), use:
scope :six, -> { where('created_at < ?', 1.month.ago) }
Upvotes: 2