Is there a way I can specify to select ALL columns in ActiveRecord except just a few. For example, for a User, I don't want to select their password hash or their email. Is this possible or do I have to manually hardcode all columns?
Thanks
write a scope like
def select_without columns select(column_names - columns.map(&:to_s)) end
Something like this?
exclude_columns = ['password', 'email'] columns = User.attribute_names.delete_if(|x| exclude_columns.include?(x)) User.select(columns)
EDIT
I forgot that we can do Array1 - Array2
A best answer:
exclude_columns = ['password', 'email'] columns = User.attribute_names - exclude_columns User.select(columns)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With