移民
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name
t.string :password_digest
t.timestamps
end
end
end
模型
class User < ActiveRecord::Base
attr_accessible :name, :password_digest
validates :name, :presence => true, :uniqueness => true
has_secure_password
end
用户注册_form
.main_form
= form_for @user do |f|
%div
= f.label :name
= f.text_field :name, :size=>40
%div
= f.label :password, "Password"
= f.password_field :password
%div
= f.label :password_confirmation, "Confirmation"
= f.password_field :password_field
%div
= f.submit 'Create user'
当我尝试注册新用户时,它会引发异常
ActiveModel::MassAssignmentSecurity::Error in UsersController#create
Can't mass-assign protected attributes: password, password_field
我做错什么了?