Home > Software design >  returning just a key from a hash field
returning just a key from a hash field

Time:02-10

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

CodePudding user response:

Try something like

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

  • Related