I am working with a ruby hash that contains key/value pairs for creating a new subscriber in my MailChimp API.
user_information = {
'fname' => 'hello world',
'mmerge1' => 'Product X' if user.product_name.present?
}
Obviously, I am getting a syntax error of syntax error, unexpected modifier_if… I am basically only wanting to add the mmerge1 based upon the conditional being true.
You can’t use
ifthat way, inside a hash-initialization block. You’ll have to conditionally add the new key/value after initializing the hash: