UsersController中的ActiveRecord :: SubclassNotFound #new

时间:2016-12-15 16:29:35

标签: ruby-on-rails

我是新手Ruby,当我从Scratch进行身份验证时出现了一些错误,这是我的错误 "单表继承机制未能找到子类:' true'。提出此错误是因为列'键入'保留用于存储继承的类。如果您没有打算将其用于存储继承类或覆盖User.inheritance_column以使用另一列来获取该信息,请重命名此列。"

我的user.rb

class UsersController < ApplicationController   
  def new       
    @user = User.new   
  end
  def create
    @user = User.new(params[:user])
    if @user.save
      flash[:notice] = "You signed up successfully"
      flash[:color]= "valid"
    else
      flash[:notice] = "Form is invalid"
      flash[:color]= "invalid"
    end
    render "new"   end

private

  def user_params
    params.require(:user).permit(:name_company, :email, :password, :password_confirmation)   end    
end

我的型号/ user.rb

class User < ApplicationRecord

  attr_accessor :password
  before_save :encrypt_password

  validates_confirmation_of :password
  validates_presence_of :password, :on => :create
  validates_presence_of :email
  validates_uniqueness_of :email

  def self.authenticate(email, password)
    user = find_by_email(email)
    if user && user.password_hash == BCrypt::Engine.hash_secret(password, user.password_salt)
      user
    else
      nil
    end
  end

  def encrypt_password
    if password.present?
      self.password_salt = BCrypt::Engine.generate_salt
      self.password_hash = BCrypt::Engine.hash_secret(password, password_salt)
    end
  end
end

任何人都可以帮助我。谢谢。

0 个答案:

没有答案