Just to add an option for people who want to exclude certain columns in every query by default can use the Rails 5 feature `ignored_columns`, which as the name suggests leaves those out.
The code is quite straightforward:
class User < ApplicationRecord
self.ignored_columns = %w[password email]
end
Please note that the [ignore_columns documentation][1] states that `You will get an error if accessing that attribute directly, so ensure all usages of the column are removed` so it may only work for cases where the columns are never required to be used.
[1]:
[To see links please register here]