title: Rails 3 how to get the current record ID in after_create
body: <p>Like the title said, I'm trying to get the ID of the record I just created, I tried to get it in the console but the ID is nil.</p>
  
  <p>Here is the print I got of self in the console at the beginning of after_create</p>
  
  <pre><code>&lt;Unit id: nil, uuid: "9f11be13-8d07-4471-a3bb-f87943966bbd", organization_id: 33, property_id: 430, door_number: "3", created_at: "2014-12-05 13:27:57", updated_at: "2014-12-05 13:27:57", deleted_at: nil, size: "5 1/2", door_number_int: 3, leases_count: 0, tasks_count: 0, notes: nil, state_id: 68, state_tasks_count: 2, current_lease_id: nil, next_lease_id: nil, state_tasks_serie: 1, state_tasks_serie_count: 2, price_asked: #&lt;BigDecimal:7fc79162cb80,'0.123E3',9(18)&gt;, availability_date: nil, comments_count: 0&gt;
  </code></pre>
  
  <p>Is there a way to get access to the record ID?</p>
  
  <p>This is what I tried so far </p>
  
  <pre><code>after_create
     self.save
  end
  
  before_save
    if self.id.present?
      # do stuff
    end
  end
  </code></pre>
  
  <p>It is not very pretty but it work</p>
  
  <p>To answer @MarekLipka : It doesn't cause an infinite loop because the record is created only once.</p>
  
  <p>I also tried to use :</p>
  
  <pre><code>after_create
     reload
  
     # do stuff if self.id
  end
  </code></pre>
  
  <p>but that doesn't seem to work.</p>
  
  <p>Like @PauloFidalgo said, I can't get the id except in the after_save method. Although it is strange to me that I can get it in the second before_save (triggered by the save in after_create). </p>