title: Rails :before_create callback not working for my Model
body: <p>I'm trying to do the following in my Rails 3 model:</p>
  
  <pre><code>require 'securerandom'
  
  class Contest &lt; ActiveRecord::Base
    attr_accessor :key
    before_create :generate_key
  
    private
  
    def generate_key
      self.key = SecureRandom.hex(3)
    end
  
  end
  </code></pre>
  
  <p>However when I create a Contest, all the fields in my table appear to be correct except the key which remains nil in my DB.</p>
  
  <p><strong>More Info:</strong></p>
  
  <p>In my rails server log, I see the following when I create a contest through my "create contest form"</p>
  
  <pre><code>SQL (0.5ms)  INSERT INTO "contests" ("category", "created_at", "description", "key", "price", "status", "time", "title", "updated_at", "user_id") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)  [["category", "camisas"], ["created_at", Wed, 15 Feb 2012 18:57:16 UTC +00:00], ["description", "test_description"], ["key", nil], ["price", 111], ["status", "In process"], ["time", "2sem"], ["title", "test_contest"], ["updated_at", Wed, 15 Feb 2012 18:57:16 UTC +00:00], ["user_id", 5]]
  </code></pre>
  
  <p>Note the ["key", nil]</p>
  
  <p>But that should be correct right?, I would guess that the key will be added by the Contest.rb :before_create callback? </p>
  
  <p>Maybe I'm miss-using SecureRandom?</p>