title: Ruby on Rails Increment Counter in Model
body: <p>I'm attempting to increment a counter in my User table from another model.</p>
  
  <pre><code>class Count &lt; ActiveRecord::Base
      belongs_to :user
  
      after_create :update_count
  
      def update_count
          user = User.find(self.user_id)
          user.increment(:count)
      end
  
  end
  </code></pre>
  
  <p>So when count is created the goal would be to increment a counter column for that user. Currently it refuses to get the user after creation and I get a nil error.</p>
  
  <p>I'm using devise for my Users</p>
  
  <p>Is this the right (best practice) place to do it? I had it working in the controllers, but wanted to clean it up.</p>
  
  <p>I'm very inexperienced with Model callbacks.</p>