Notes posted by dreadpirateshawn
RSS feed"Class methods on your model are automatically available on scopes."
The final example above – “Class methods on your model are automatically available on scopes.” – contains a subtle but vital change from earlier versions of the doc – namely, “pluck” (current example) vs “map” (old example). The former works, the latter does not. See http://github.com/rails/rails/issues/21943 for confirmation that the old documentation is incorrect, and for a workaround.
(Spoiler alert: Use
all.map(&:title)
instead of just
map(&:title)
in order to achieve the same effect.)
"Class methods on your model are automatically available on scopes."
The final example above – “Class methods on your model are automatically available on scopes.” – does not work as written. See http://github.com/rails/rails/issues/21943 for confirmation that the old documentation is incorrect, and for a workaround.
(Spoiler alert: Use
all.map(&:title)
instead of just
map(&:title)
in order to achieve the same effect.)