cloud9でwebアプリケーションを作っているのですが、deviseで新規登録した時にActiveRecord::AssociationTypeMismatch in Devise::RegistrationsController#create
のエラーが発生します。いまいちこのエラーの意味がわからずどこをどう改善すれば良いかわかりません。
ネットで調べてみても良い情報が見つからず困っています。
仕様
・ログイン機能はdeviseを使っています。
・アソシエーションを使っています。
routes.rb
Rails.application.routes.draw do devise_for :customers devise_for :admins namespace :public do get 'sign_in' => 'sessions#new' get 'sign_up' => 'registrations#new' resources :items,only:[:index,:show,:create] resources :homes,only:[:index] resources :cart_items,only:[:show,:create,:update,:index,:destroy] delete '/cart_items/destroy_all' => 'cart_items#destroy_all', as:'cart_items_destroy_all' resources :orders,only:[:new,:create] end namespace :admin do get 'sign_in' => 'sessions#new' resources :items, only: [:create, :index, :show, :edit, :update, :destroy,:new] resources :genres, only: [:index, :create,:edit, :update] resources :customers, only: [:index, :create, :new, :update, :destroy, :show] end root 'admin/items#top' get 'about' =>'admin/items#about' end
application.html.erb
lass ApplicationController < ActionController::Base before_action :configure_permitted_parameters, if: :devise_controller? protected def after_sign_out_path_for(resource) root_path end def after_sign_in_path_for(resource) case resource when Admin admin_root_path(resource) when Customer public_items_path(resource) end end def configure_permitted_parameters devise_parameter_sanitizer.permit(:sign_up, keys: [:name,:email,:first_name,:last_name_kana,:first_name_kana,:address,:postal_code,:email,:telephone_number,:is_deleted]) end end
new.html.erb
<div class="container"> <div class="row"> <div class="col mx-auto w-75"> <div class="customer-title"> <h4 class="bg-light text-center m-4" style="width:20%;">新規会員登録</h4> </div> <%= form_for (@customer),url: customer_registration_path do |f| %> <%= render "devise/shared/error_messages", resource: resource %> <div class="customer-list d-flex"> <div class="customer-left"> <div class="customer-item"> <p>名前</p> <p>フリガナ</p> <p>メールアドレス</p> <p>郵便便番号(ハイフンなし)</p> <p>住所</p> <p>電話番号(ハイフンなし)</p> <p>パスワード(6文字以上)</p> <p>パスワード(確認用)</p> </div> </div> <div class="customer-right pl-4"> <div class="customer-name d-flex p-1"> (姓) <%= f.text_field :last_name %> (名) <%= f.text_field :first_name %> </div> <div class="customer-name2 d-flex p-1"> (セイ) <%= f.text_field :last_name_kana %> (メイ) <%= f.text_field :first_name_kana %> </div> <div class="customer-email p-1"> <%= f.email_field :email, autofocus: true, autocomplete: "email" %> </div> <div class="customer-postal_code p-1"> <%= f.text_field :postal_code %> </div> <div class="customer-street-address p-1"> <%= f.text_field :address %> </div> <div class="customer-phone p-1"> <%= f.telephone_field :telephone_number %> </div> <div class="customer-password p-1"> <% if @minimum_password_length %> <% end %> <%= f.password_field :password, autocomplete: "new-password" %> </div> <div class="customer-password2 p-1"> <%= f.password_field :password_confirmation, autocomplete: "new-password" %> </div> <div class="actions mt-3"> <%= f.submit "新規登録",:class=>"bg-success text-white border border-light",:style=>"padding-right:50px; padding-left:50px;" %> </div> </div> </div> <% end %> <div class="customer-login"> <h4 class="bg-light w-25 m-4 text-center">既に登録済みの方</h4> <p class="m-2"><%= link_to "こちら", new_customer_session_path,:class=>"m-2" %> からログインしてください</p> </div> </div> </div>
customer.rb
class Customer < ApplicationRecord # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable has_many :cart_items, dependent: :destroy has_many :orders, dependent: :destroy belongs_to :address,optional: true end
あなたの回答
tips
プレビュー