title: How to initialize an ActiveRecord with values in Rails?
body: <p>In plain java I'd use:</p>
  
  <pre><code>public User(String name, String email) {
    this.name = name;
    this.email = f(email);
    this.admin = false;
  }
  </code></pre>
  
  <hr>
  
  <p>However, I couldn't find a simple standard way to do in rails (3.2.3), with ActiveRecords.</p>
  
  <h3>1. override initialize</h3>
  
  <pre><code>def initialize(attributes = {}, options = {})
    @name  = attributes[:name]
    @email = f(attributes[:email])
    @admin = false
  end
  </code></pre>
  
  <p>but it might be missed when creating a <a href="http://blog.dalethatcher.com/2008/03/rails-dont-override-initialize-on.html" rel="noreferrer">record from the DB</a></p>
  
  <h3>2. using the <code>after_initialize</code> callback</h3>
  
  <p>by overriding it:</p>
  
  <pre><code>def after_initialize(attributes = {}, options = {})
    ...
  end
  </code></pre>
  
  <p>or with the macro:</p>
  
  <pre><code>after_initialize : my_own_little_init
  def my_own_little_init(attributes = {}, options = {})
    ...
  end
  </code></pre>
  
  <p>but there may be <a href="https://stackoverflow.com/questions/328525/what-is-the-best-way-to-set-default-values-in-activerecord">some deprecation issues</a>.</p>
  
  <p>There are some <a href="https://stackoverflow.com/questions/4906704/how-to-use-after-initialize-in-rails-3">other</a> links <a href="https://stackoverflow.com/questions/1550688/how-do-i-create-a-default-value-for-attributes-in-rails-activerecords-model">in SO</a>, but they may be out-of-date.</p>
  
  <hr>
  
  <p>So, <em>what's the correct/standard method to use?</em></p>