Неверный параметр в рельсах, хотя params .permit (ted) - PullRequest
1 голос
/ 23 апреля 2020

У меня есть проект rails (6.0.2.2) с устройством (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

my 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

Я использую сгенерированные по умолчанию учителя / registration / new. html .erb, поэтому я думаю, что здесь нет проблем.

Я добавил строку config / initializers / devise.rb:

config.authentication_keys = [:username]

, чтобы изменить вход по умолчанию с электронной почты на имя пользователя, но я не думаю, что это проблема, потому что студенты снова могут создать учетную запись.

Спасибо за вашу помощь!

1 Ответ

0 голосов
/ 23 апреля 2020

@ Тихана Я не знаю, проверяли ли вы это уже. ссылка на сайт. Если нет, то это может помочь https://github.com/heartcombo/devise#strong -параметры

...