deviseで複数モデルを管理する場合の実装。ユーザー新規登録をした後にトップページに遷移させたい。
Railsでdeviseを用いて実装をしています。
ユーザーを2パターンに分けたため複数モデルで管理をする実装をしており、ユーザーの新規登録完了後トップページに遷移させたいのですが、以下のエラーが出ます。
テーブルにも情報が保存されません。
Routing Error No route matches [POST] "/trainers/sign_up" Rails.root: /Users/horitakuya/projects/dm-space Application Trace | Framework Trace | Full Trace Routes Routes match in priority from top to bottom
該当のソースコード
Rails
1Rails.application.routes.draw do 2 devise_for :cliants, controllers: { 3 sessions: 'cliants/sessions', 4 passwords: 'cliants/passwords', 5 registrations: 'cliants/registrations' 6 } 7 devise_for :trainers, controllers: { 8 sessions: 'trainers/sessions', 9 passwords: 'trainers/passwords', 10 registrations: 'trainers/registrations' 11 } 12 root 'tops#index' 13end
ragistrasitons_controller.rb
1# frozen_string_literal: true 2 3class Trainers::RegistrationsController < Devise::RegistrationsController 4 before_action :configure_sign_up_params, only: [:create] 5 # before_action :configure_account_update_params, only: [:update] 6 7 # GET /resource/sign_up 8 def new 9 super 10 end 11 12 # POST /resource 13 def create 14 @trainer = Trainer.new(configure_sign_up_params) 15 end 16 17 # GET /resource/edit 18 # def edit 19 # super 20 # end 21 22 # PUT /resource 23 # def update 24 # super 25 # end 26 27 # DELETE /resource 28 # def destroy 29 # super 30 # end 31 32 # GET /resource/cancel 33 # Forces the session data which is usually expired after sign 34 # in to be expi red now. This is useful if the user wants to 35 # cancel oauth signing in/up in the middle of the process, 36 # removing all OAuth session data. 37 # def cancel 38 # super 39 # end 40 41 # protected 42 43 # If you have extra params to permit, append them to the sanitizer. 44 def configure_sign_up_params 45 devise_parameter_sanitizer.permit(:sign_up, keys: [:nickname, :first_name, :last_name, :profile]) 46 end 47 48 # If you have extra params to permit, append them to the sanitizer. 49 # def configure_account_update_params 50 # devise_parameter_sanitizer.permit(:account_update, keys: [:attribute]) 51 # end 52 53 # The path used after sign up. 54 def after_sign_up_path_for(resource) 55 root_path(resource) 56 end 57 58 # The path used after sign up for inactive accounts. 59 # def after_inactive_sign_up_path_for(resource) 60 # super(resource) 61 # end 62end
html.erb
1<%= form_with model: @trainer, url: new_trainer_registration_path, class: 'registration-main', local: true do |f| %> 2<div class='form-wrap'> 3 <div class='gorm-header'> 4 <h1 class='form-header-text'> 5 会員情報入力 6 </h1> 7 </div> 8 <%= render 'shared/error_messages', momdel: f.object %> 9 <div class='form-group'> 10 <div class='form-text-wrap'> 11 <label class="form-text">ニックネーム</label> 12 <span class="indispensable">必須</span> 13 </div> 14 <%= f.text_area :nickname, class:"input-default", id:"nickname", placeholder:"例) 田中太郎", maxlength:"40" %> 15 </div> 16 <div class='form-group'> 17 <div class='form-text-wrap'> 18 <label class='form-text'>メールアドレス</label> 19 <span class='indispensable'>必須</span> 20 </div> 21 <%= f.email_field :email, class:"input-default", id:"email", placeholder:"PC・携帯どちらでも可", autofocus: true %> 22 </div> 23 <div class="form-group"> 24 <div class="form-text-wrap"> 25 <label class="form-text">パスワード</label> 26 <span class="indispensable">必須</span> 27 </div> 28 <%= f.password_field :password, class:"input-default", id:"password", placeholder:"6文字以上の半角英数字" %> 29 <p class='info-text'>英字と数字の両方を含めて設定してください</p> 30 </div> 31 <div class="form-group"> 32 <div class="form-text-wrap"> 33 <label class="form-text">パスワード(確認)</label> 34 <span class="indispensable">必須</span> 35 </div> 36 <%= f.password_field :password_confirmation, class:"input-default", id:"password-confirmation", placeholder:"同じパスワードを入力してください" %> 37 </div> 38 <div class="form-group"> 39 <div class="form-text-wrap"> 40 <label class="form-text">お名前(全角)</label> 41 <span class="indispensable">必須</span> 42 </div> 43 <div class="input-name-wrap"> 44 <%= f.text_area :last_name, class:"input-name", id:"last-name", placeholder:"例) 田中" %> 45 <%= f.text_area :first_name, class:"input-name", id:"first-name", placeholder:"例) 太郎" %> 46 </div> 47 </div> 48 <div class="form-group"> 49 <div class="form-text-wrap"> 50 <label class="form-text">プロフィール</label> 51 <span class="indispensable">必須</span> 52 </div> 53 <%= f.text_field :profile, class:"input-default", id:"profile" %> 54 </div> 55 <div class="register-btn"> 56 <%= f.submit "新規登録" ,class:"registar-red-btn" %> 57 </div> 58<% end %> 59</div>
試したこと
ルーティングの記述に誤りがないかの確認や、devise複数モデル管理におけるコントローラーに記述しなければならないことを調べたりしましたが、解決できずお力をお借りできますと幸いです。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/11/01 08:11
2021/11/01 08:33
2021/11/01 08:53
2021/11/01 09:14
2021/11/01 09:57
2021/11/01 11:30
2021/11/01 11:51 編集
2021/11/01 11:53
2021/11/01 12:12
2021/11/01 12:47
2021/11/01 12:58