user2101461
user2101461

Reputation: 309

Rails – How to use if else statement in array?

I'm integrating infusionsoft with our rails app and we can create contacts using their API using this call, and passing the data through an array...

Infusionsoft.contact_add_with_dup_check({'Email' => contact.email, 'FirstName' => (contact.name if contact.name.present?)}, 'Email')

However, I want to be able to post additional contact info to their API if the contact in our rails app has more data. Such as if name or city is present. My attempt at checking if contact.name is present returns an error.

How can I do an if else statement within the array?

Upvotes: 1

Views: 628

Answers (1)

Kinaan Khan Sherwani
Kinaan Khan Sherwani

Reputation: 1534

contact_info = {'Email' => contact.email}
contact_info.merge!({'FirstName' => contact.name }) if contact.name.present?
Infusionsoft.contact_add_with_dup_check(contact_info, 'Email')

you can use a code same as in line#2 in case of city

Upvotes: 1

Related Questions