title: Rails update_attributes if value is present, else nil
body: <p>On Rails 5. </p>
  
  <p>I have a <code>Service</code> model with <code>access_token</code> and <code>expires_at</code> attributes.</p>
  
  <p>I am making an API request to fetch the access token and expiration, however, in many cases the expires_at is not present, in which case I would like the value to be nil. </p>
  
  <p>In my controller, I am doing something basic like:</p>
  
  <pre><code>@service.update_attributes(
      access_token: api_response["access_token"],
      expires_at: Time.at(api_response["credentials"]["expires_at"])
    )
  </code></pre>
  
  <p>What is the correct way to only update <code>expires_at</code> if the api response contains it? </p>
  
  <p>I was thinking of setting a variable if present:</p>
  
  <pre><code>if api_response["credentials"]["access_token"].present?
    expiry = api_response["credentials"]["access_token"]
  else
    expiry = nil
  end
  </code></pre>
  
  <p>then updating like... </p>
  
  <pre><code>@service.update_attributes(expires_at: expiry)
  </code></pre>
  
  <p>But this doesn't seem like the correct way to do it. And if I need to check multiple values from the api response, there would be a lot of extra code just to check presence. </p>
  
  <p>What would be the Rails way to do this? Having a hard time finding an answer. </p>