首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >rails中不允许的参数,即使参数.permit(ted)

rails中不允许的参数,即使参数.permit(ted)
EN

Stack Overflow用户
提问于 2020-04-23 12:21:16
回答 1查看 35关注 0票数 1

我有一个rails (6.0.2.2)项目和devise (4.7.1)项目,有两种类型的帐户:教师和学生。学生可以成功地报名,但由于某种原因,老师出了问题。当我尝试创建一个测试帐户时,我得到

代码语言:javascript
复制
Unpermitted parameter: :email

错误消息和我的信息未保存在数据库中。

迁移:

代码语言:javascript
复制
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:

代码语言:javascript
复制
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中添加了一行:

代码语言:javascript
复制
config.authentication_keys = [:username]

要将默认登录从电子邮件更改为用户名,但我不认为这是问题,因为学生可以再次创建帐户。

谢谢你的帮忙!

EN

回答 1

Stack Overflow用户

发布于 2020-04-23 17:28:42

@Tijana我不知道你是否已经检查过了。链接。如果没有,这可能会对https://github.com/heartcombo/devise#strong-parameters有所帮助

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61379322

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档