我有一个rails (6.0.2.2)项目和devise (4.7.1)项目,有两种类型的帐户:教师和学生。学生可以成功地报名,但由于某种原因,老师出了问题。当我尝试创建一个测试帐户时,我得到
Unpermitted parameter: :email错误消息和我的信息未保存在数据库中。
迁移:
class DeviseCreateTeachers < ActiveRecord::Migration[6.0]
def change
create_table :teachers do |t|
## Database authenticatable
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: ""
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
t.string :username
t.string :name
t.string :neighborhood
t.integer :pet_skin
t.integer :pet_eyes
t.integer :pet_face
t.integer :pet_accessories
## Trackable
# t.integer :sign_in_count, default: 0, null: false
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.string :current_sign_in_ip
t.string :last_sign_in_ip
## Confirmable
t.string :confirmation_token
t.datetime :confirmed_at
t.datetime :confirmation_sent_at
# t.string :unconfirmed_email # Only if using reconfirmable
## Lockable
t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
t.string :unlock_token # Only if unlock strategy is :email or :both
t.datetime :locked_at
t.timestamps null: false
end
add_index :teachers, :email, unique: true
add_index :teachers, :reset_password_token, unique: true
# add_index :teachers, :confirmation_token, unique: true
# add_index :teachers, :unlock_token, unique: true
end
end我的teacher_controller.rb:
class TeacherController < ApplicationController
private
def sign_up_params
params.require(:teacher).permit(:email, :username, :name, :password, :password_confirmation, :neighborhood, :pet_skin, :pet_eyes, :pet_face)
end
def account_update_params
params.require(:teacher).permit(:username, :password, :password_confirmation, :current_password)
end
end我使用默认的生成教师/注册/new.html.erb,所以我认为这里没有问题。
我在config/initializers/devise.rb中添加了一行:
config.authentication_keys = [:username]要将默认登录从电子邮件更改为用户名,但我不认为这是问题,因为学生可以再次创建帐户。
谢谢你的帮忙!
发布于 2020-04-23 17:28:42
@Tijana我不知道你是否已经检查过了。链接。如果没有,这可能会对https://github.com/heartcombo/devise#strong-parameters有所帮助
https://stackoverflow.com/questions/61379322
复制相似问题