我是Rails 4开发和轨道的新手.我红色官方"入门指南"指南,其中显示如何创建博客.所以我想从0注册,auth系统做我自己的.
在创建新用户时,我收到此错误.我不明白我做错了什么.有什么建议?
Git回购:https: //github.com/pumpurs/auth
UsersController中的ActiveRecord :: UnknownAttributeError#创建未知属性:密码
class UsersController < ApplicationController
def new
@user = User.new
end
def create
@user = User.new(params[:user].permit(:password, :email, :password_confirmation))
end
private
def user_params
params.require(:user).permit(:password, :email, :password_confirmation)
end
end
Run Code Online (Sandbox Code Playgroud)
型号文件:
class User < ActiveRecord::Base
before_save :encrypt_password
validates_confirmation_of :password
validates_presence_of :password, :on => :create
validates_presence_of :email
validates_uniqueness_of :email
def enrypt_password
if password.present?
self.password_salt = BCript::Engine.generate_salt
self.password_hash = BCript::Engine.generate.hash_seret(password, password_salt)
end
end
end
Run Code Online (Sandbox Code Playgroud)