Code Snippet for getting a certain field from a scoped model

This comes up a lot and I keep reinventing it:

@user.cars.map(&:name)

Note that pluck doesn’t work because it’s a class method not an instance method.

Comments are closed.