Notes posted by dreadpirateshawn
RSS feed![Default_avatar_30](https://www.gravatar.com/avatar/dc3ee45902521594d55e2b8e3de5cf8e?default=http://apidock.com/images/default_avatar_30.png&size=30)
"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.)
![Default_avatar_30](https://www.gravatar.com/avatar/dc3ee45902521594d55e2b8e3de5cf8e?default=http://apidock.com/images/default_avatar_30.png&size=30)
"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.)