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.
Below is my model:
class User
include ActiveModel::Validations
validates :name, :presence => true
validates :email, :presence => true
validates :password, :presence => true, :confirmation => 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
And here's my controller:
class UsersController < ApplicationController
def new
@user = User.new
@title = "Sign up"
end
end
And my view is:
<h1>Sign up</h1>
<%= form_for(@user) do |f| %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :email %><br />
<%= f.text_field :email %>
</div>
<div class="field">
<%= f.label :password %><br />
<%= f.password_field :password %>
</div>
<div class="field">
<%= f.label :password_confirmation, "Confirmation" %><br />
<%= f.password_field :password_confirmation %>
</div>
<div class="actions">
<%= f.submit "Sign up" %>
</div>
<% end %>
But when I load this view in the browser, I am getting an exception:
undefined method 'to_key' for User:0x104ca1b60
Can anyone please help me with this?
Many thanks in advance!