尝试使用设备注册用户时的ActiveRecord :: AssociationTypeMismatch

我正在尝试使用devise gem在注册过程中附加嵌套字段。 我想在一个请求中创建用户创建后属于User的video。

表单从registrations_controller.rb发送post to create方法,并在sign_up参数处失败

new.html.erb

 <input name="authenticity_token" type="hidden" value=""/> 

( characters minimum)



registrations_controller.rb

 def create super end private def sign_up_params params.require(:user).permit(:email, :password, password_confirmation, videos: [:title, desc]) end 

用户模型

 class User < ApplicationRecord # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable has_many :videos, inverse_of: :user accepts_nested_attributes_for :videos end 

video模型

 class Video < ApplicationRecord belongs_to :user end 

安慰

 Started POST "/users" for 127.0.0.1 at 2018-06-14 17:36:35 +0200 Processing by Users::RegistrationsController#create as JS Parameters: {"utf8"=>"✓", "authenticity_token"=>"XhRMYudWgjw4LMm1PzqOtRzy+MfdYotwBg6pZihGkJFTuBTDFd1iaXhXGmVNAoyQrCKOy9Nhy4gW7zJgGmXGvA==", "user"=>{"email"=>"abc@gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "videos"=>{"title"=>"", "desc"=>""}}} Completed 500 Internal Server Error in 2ms (ActiveRecord: 0.0ms) ActiveRecord::AssociationTypeMismatch (Video(#70239190589100) expected, got ["title", ""] which is an instance of Array(#19511580)): app/controllers/users/registrations_controller.rb:16:in `create' 

更新1

registrations_controller.rb

 class Users::RegistrationsController < Devise::RegistrationsController before_action :configure_sign_up_params, only: [:create], if: :devise_controller? protected def configure_sign_up_params devise_parameter_sanitizer.permit(:sign_up) { |u| u.permit(:email, :password, :password_confirmation, videos: [:title, :desc]) } end end 

问题依然存在