我不想让我的模型与数据库有任何关系,而是试图使用主动的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
这里是我的控制者:
class UsersController < ApplicationController
def new
@user = User.new
@title = "Sign up"
end
end
我认为:
<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 %>
但是,当我在浏览器中提出这一看法时,我就成为一个例外:
undefined method to_key for User:0x104ca1b60
没有人会帮助我这样做?
很多事事事事事事事事事事事事前会!