returning just a key from a hash field

Viewed 39

I have an ActivityPart model that has a field called activity_json. this field is a hash and has a key named "image". How do I select all "image" from the activity_json field? I did something like this but it didn't work:

x = ActivityPart.all.pluck(activity_json: ['image'])

my idea is to return all 'image' from the activiy_json field

1 Answers

Try something like

ActivityPart.select("activity_json->'image' as image").map(&:image)

Related