TIL #1 : How to pluck jsonb fileds in Rails

TIL #1 : How to pluck jsonb fileds in Rails

If you have a jsonb field in your Active record object and you want some nested value you can use pluck

Example: Lets say your Users model has a jsonb attribuite metadata which has a nested key location which in turn has city you can get the value of city like

Users.pluck("metadata -> 'location' -> 'city'") => ["London", "Liverpool"]