Rails3: Undefined Method Includes Values
Thursday, 9 September 2010
I can across an error in Rails3 today when I was trying to implement a scope.
scope :latest, order("created_at asc").first
When trying to run that Scope I’d get
undefined method 'includes_values' for <#Product:rarrarrar>
It had me scratching my head since the trace showed me nothing. So I went through the activerecord codebase, and sure enough it was something stupid that I did.
The scope should return an ActiveRecord object, and not a result set. So simply removing the .first off my scope resulting in a working scope
scope :latest, order("created_at asc")
Its a simple fix, but googling came up with nothing. So I hope this helps someone else who comes across this error.
No. 1 — July 22nd, 2011 at 5:33 pm
Yes, this helped immensely! Exactly the problem I’ve been having.
No. 2 — August 9th, 2011 at 5:27 pm
Yes, was very helpful, as it is now also on google :) Thanks!
No. 3 — August 24th, 2011 at 5:24 pm
Very helpful, thanks for posting this Mark.
No. 4 — September 8th, 2011 at 9:17 pm
+1 Helped me
No. 5 — January 16th, 2012 at 1:22 pm
Thanks, helped me today.