title: Ruby on Rails: How can i iterate over params and convert any empty strings into nil values in a controller?
body: <p>Rails newbie here.</p>
  
  <p>I have an integration with stripe where users can update the billing address on their card, however, stripe doesn't accept empty strings, only nil values, and it's possible that users won't need to fill in the second address line for example. </p>
  
  <p>How would I go about iterating through params received from a form and convert empty strings into nil?</p>
  
  <p>I have a Stripe Tool module that handles stripe related tasks.</p>
  
  <p>In my controller i have:</p>
  
  <pre><code>   def add_billing_address
     account_id = current_user.account_id
     account = Account.find_by(id: account_id)
     stripe_id = account.stripe_customer_id
  # convert params empty strings to nil here
     StripeTool.add_billing_address(stripe_id: stripe_id,
                                  stripe_token: params[:stripeToken],
                                  address_line1: params[:address_line1],
                                  address_line2: params[:address_line2],
                                  address_city: params[:address_city],
                                  address_state: params[:address_state],
                                  address_zip: params[:address_zip]
                                  )
  # redirects and error handling happens after this
  </code></pre>