创建新用户时,自定义属性为 nil 。
application_controller.rb
TypeError: names_to_saveables must be a dict mapping string names to Tensors/Variables. Not a variable: Tensor("Const:0", shape=(128, 14987), dtype=float32)
User.rb
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
before_action :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
# devise_parameter_sanitizer.permit(:sign_up) { |u| u.permit(:first_name, :last_name, :email, :password, :password_confirmation) }
# devise_parameter_sanitizer.permit(:account_update) { |u| u.permit(:first_name, :last_name, :email, :password, :password_confirmation, :current_password) }
devise_parameter_sanitizer.permit(:sign_up, keys: [:first_name, :last_name])
devise_parameter_sanitizer.permit(:account_update, keys: [:first_name, :last_name])
end
end
seeds.rb
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable, :confirmable
validates :email, :password, :password_confirmation, :first_name, :last_name, presence: true
attr_accessor :first_name, :last_name
end
输出:
User.create(first_name: "User", last_name: "Help", email: "account@email.com", password: "password", password_confirmation: "password")
我不确定我哪里出错...我按照Devise指南阅读了几个类似问题的Stack Overflow问题(question)。我试过attr_accessible无济于事。
更新:db / schema.rb
#<User id: 5, email: "account@email.com", created_at: "2017-01-31 02:44:32", updated_at: "2017-01-31 02:44:32", first_name: nil, last_name: nil>
答案 0 :(得分:0)
从模型中删除此行
attr_accessor :first_name, :last_name