Rails3: Undefined Method Includes Values

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.

5 Responses to “Rails3: Undefined Method Includes Values”

  1. Peter Hicks writes:

    Yes, this helped immensely! Exactly the problem I’ve been having.

  2. Muhammad Härter writes:

    Yes, was very helpful, as it is now also on google :) Thanks!

  3. Chris writes:

    Very helpful, thanks for posting this Mark.

  4. Kyle writes:

    +1 Helped me

  5. Vadim writes:

    Thanks, helped me today.

Leave a Reply



Nice job!
You now have 30 lives.
Use them wisely, my friend.

Konami Easter Egg by Adrian3.com