0

I am currently using the facebook-ruby-business-sdk to manage ads on Facebook.

I have written a method to update a FacebookAds::AdSet object.

# Fetch the adset
adset = FacebookAds::AdSet.get(source_adset_id, session)

# Set the new name
adset.name = 'Test name'

# Save the Adset
adset.save

That works and sets the name, but if i try to set a nested property like so:

adset = FacebookAds::AdSet.get(source_adset_id, session)

# Set the new minimum age 
adset.targeting.age_min = 20

# this is the adset's new min age (should be 20)
p adset.age_min
#=> 18

# Save the Adset
adset.save

When i set the adset.targeting.age_min the value is never set, this goes for any nested value that i try to set.

Am i setting this value the wrong way? Is there any other way to approach this?

ricks
  • 3,154
  • 31
  • 51

1 Answers1

0

I guess their gem does not allow to update the child's attributes.

My workaround was creating a targeting hash like so:

targeting = {
    age_min: 20
}

Once you have your hash created, just set it to the object like so:

adset.targeting = targeting

And finally:

adset.save
ricks
  • 3,154
  • 31
  • 51