title: Set default random column value in ActiveRecord model
body: <p>got 2 models:</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    has_many :posts
  end
  </code></pre>
  
  <p>and</p>
  
  <pre><code>class Post &lt; ActiveRecord::Base
    belongs_to :user
  end
  </code></pre>
  
  <p>the Posts table has a column: u_hash. This is supposed to be a randomly generated identifying hash (for public viewing). What is the best way to generate this hash and how can I add it to the table? The idea is that all this will happen in the background and not be visible to the user (no hidden field in the form). The database used is MySQL if that could help me out somehow.</p>
  
  <p>Thanks in advance!
  J</p>