Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unknown attribute rails 4

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
like image 597
andris Avatar asked Apr 20 '26 21:04

andris


1 Answers

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.

like image 134
Brad Werth Avatar answered Apr 23 '26 13:04

Brad Werth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!