Query on console
User.select('email','dob')
returns,
[#<User:0x000000084a9b08 id: nil, email: "[email protected]">,
Why am I getting id attributes in rails 4? How to get rid of this?
Pluck only returns the values if you want keys and values then try this:
User.select('email','dob').as_json(:except => :id)
In my case the desired result was a JSON object. So, inside the as_json method
you can exclude any column you desire
(additionally you can invoke object methods or access associated tables as well)
This will give you desired output
User.pluck(:email, :dob)
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