title: Rails 6 - NoMethodError (undefined method `titleize' for nil:NilClass)
body: <p>I looked through questions here about my error, but they are seems unrelated, hence this post.
  I have a 'capitalize_names' method in my UserProfile model that throw this error when I update attributes in the console. But the model gets updated even though I get this error. I tried making my instance method private, protected. But the results is the same. Not sure what I'm missing here.
  Big thank you in advance for your help. </p>
  
  <p>My model:</p>
  
  <pre><code>class UserProfile &lt; ApplicationRecord
    belongs_to :user
    before_update :capitalize_names
  
   # i tried protected or private still gets the same result!!
   def capitalize_names
     self.first_name = self.first_name.titleize
     self.last_name = self.last_name.titleize
   end
  end
  </code></pre>
  
  <p>Here's my console out put:</p>
  
  <pre><code>irb(main):004:0&gt; u
  =&gt; #&lt;User id: 25, username: "somename1", email: "bhati12345@gmail.com", created_at: "2019-09-14 14:09:46", updated_at: "2019-09-14 14:09:46"&gt;
  
  irb(main):005:0&gt; u.profile
  =&gt; #&lt;UserProfile id: 25, first_name: nil, last_name: nil, user_id: 25, pop_value: nil, time_zone: nil, country: nil, sketch_profile: {}, profile_image: nil, logo: nil, created_at: "2019-09-14 14:09:46", updated_at: "2019-09-14 14:09:46", gender: "male"&gt;
  
  irb(main):006:0&gt; u.profile.update(first_name: 'somecool name')
  Traceback (most recent call last):
      2: from (irb):6
      1: from app/models/user_profile.rb:16:in `capitalize_names'
  NoMethodError (undefined method `titleize' for nil:NilClass)
  </code></pre>
  
  <p>But, as you can see my model still got successfully updated...</p>
  
  <pre><code>irb(main):007:0&gt; u.profile
  =&gt; #&lt;UserProfile id: 25, first_name: "Somecool Name", last_name: nil, user_id: 25, pop_value: nil, time_zone: nil, country: nil, sketch_profile: {}, profile_image: nil, logo: nil, created_at: "2019-09-14 14:09:46", updated_at: "2019-09-14 14:10:52", gender: "male"&gt;
  </code></pre>