문제

im new into Rails 4 development and rails in general. I red official "getting started with rails" guide where it is shown how to create blog. So I want to do my own from 0 registration, auth system.

While creating new user I get this error. I do not understand what I am doing wrong. Any advice?

Git repo: https://github.com/pumpurs/auth

ActiveRecord::UnknownAttributeError in UsersController#create unknown attribute: password

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

Model file:

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
도움이 되었습니까?

해결책

You need to add attr_accessor :password to your User model, to provide a non-db-backed attribute to use to base your db-backed password_hash attribute off of.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top