【问题标题】:Umpermitted parameter in rails devise, even though params .permit(ted)rails 设计中不允许的参数,即使 params .permit(ted)
【发布时间】:2020-04-23 22:17:50
【问题描述】:

我有带有设计 (4.7.1) 的 rails (6.0.2.2) 项目,有两种类型的帐户:教师和学生。学生可以注册成功,但是老师因为某种原因出现了问题。当我尝试创建一个测试帐户时,我得到了

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

我使用的是默认生成的 Teachers/registration/new.html.erb 所以我认为这里没有问题。

我确实在 config/initializers/devise.rb 中添加了一行:

config.authentication_keys = [:username]

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

感谢您的帮助!

【问题讨论】:

    标签: ruby-on-rails devise


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多