title: ActiveModel - View - Controller in Rails instead of ActiveRecord?
body: <p>I'm trying to use ActiveModel instead of ActiveRecord for my models because I do not want my models to have anything to do with the database. </p>
  
  <p>Below is my model:</p>
  
  <pre><code>class User
    include ActiveModel::Validations
    validates :name, :presence =&gt; true
    validates :email, :presence =&gt; true
    validates :password, :presence =&gt; true, :confirmation =&gt; true
  
    attr_accessor :name, :email, :password, :salt
    def initialize(attributes = {})
      @name  = attributes[:name]
      @email = attributes[:email]
      @password = attributes[:password]
      @password_confirmation = attributes[:password_confirmation]
    end
  end
  </code></pre>
  
  <p>And here's my controller:</p>
  
  <pre><code>class UsersController &lt; ApplicationController
    def new
      @user = User.new
      @title = "Sign up"
    end
  end
  </code></pre>
  
  <p>And my view is:</p>
  
  <pre><code>&lt;h1&gt;Sign up&lt;/h1&gt;
  
  &lt;%= form_for(@user) do |f| %&gt;
  &lt;div class="field"&gt;
      &lt;%= f.label :name %&gt;&lt;br /&gt;
      &lt;%= f.text_field :name %&gt;
  &lt;/div&gt;
  &lt;div class="field"&gt;
      &lt;%= f.label :email %&gt;&lt;br /&gt;
      &lt;%= f.text_field :email %&gt;
  &lt;/div&gt;
  &lt;div class="field"&gt;
      &lt;%= f.label :password %&gt;&lt;br /&gt;
      &lt;%= f.password_field :password %&gt;
  &lt;/div&gt;
  &lt;div class="field"&gt;
      &lt;%= f.label :password_confirmation, "Confirmation" %&gt;&lt;br /&gt;
      &lt;%= f.password_field :password_confirmation %&gt;
  &lt;/div&gt;
  &lt;div class="actions"&gt;
      &lt;%= f.submit "Sign up" %&gt;
  &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>But when I load this view in the browser, I am getting an exception:</p>
  
  <pre><code>undefined method 'to_key' for User:0x104ca1b60
  </code></pre>
  
  <p>Can anyone please help me with this?</p>
  
  <p>Many thanks in advance!</p>