アプリケーションを作成しています。
deviseを2つ作って userとdoctorでログイン画面を分けています。
userの方では新規登録画面に遷移し登録、ログインができますが、もう一つのdoctorの新規会員登録画面にいくと元のdoctors/index画面に戻ってしまいます。
ルーティングパス、ビューの準備はできましたが、何が原因かわかりません。。
ruby '2.6.5'
rails, '6.0.0'
routes.rb
ruby
1 2Rails.application.routes.draw do 3 devise_for :doctors, controllers: { 4 sessions: 'doctors/sessions', 5 passwords: 'doctors/passwords', 6 registrations: 'doctors/registrations' 7 } 8 devise_for :users, controllers: { 9 sessions: 'users/sessions', 10 passwords: 'users/passwords', 11 registrations: 'users/registrations', 12 13 } 14 resources :users, only: [:index, :show] 15 resources :doctors, only: [:index, :show] 16 root to: 'medicines#index' 17 resources :medicines 18end 19
doctors/registrations/new.html.erb
ruby
1 2<%= form_with model:@doctor, url: doctor_registration_path, class: 'registration-main', local: true do |f| %> 3 <%= render "devise/shared/error_messages", resource: resource %> 4 <h2>新規登録</h2> 5 <div class="field"> 6 <%= f.label :doctor_name, class:"input-default" %><br /> 7 <%= f.text_field :doctor_name, class:"input-default", autofocus: true, autocomplete: "doctor_name" %> 8 </div> 9 10 11 <div class="field"> 12 <%= f.label :email, class:"input-default" %><br /> 13 <%= f.email_field :email, class:"input-default", autofocus: true, autocomplete: "email" %> 14 </div> 15 16 <div class="field"> 17 <%= f.label :password, class:"input-default" %> 18 <% if @minimum_password_length %> 19 <em>(<%= @minimum_password_length %> characters minimum)</em> 20 <% end %><br /> 21 <%= f.password_field :password, class:"input-default", autocomplete: "new-password" %> 22 </div> 23 24 <div class="field"> 25 <%= f.label :password_confirmation, class:"input-default" %><br /> 26 <%= f.password_field :password_confirmation, class:"input-default", autocomplete: "new-password" %> 27 </div> 28 29 <div class="field"> 30 <%= f.label :experience, class:"input-default"%><br /> 31 <%= f.text_field :experience, class:"input-default", autocomplete: "experience" %> 32 </div> 33 34 <div class="field"> 35 <%= f.label :special_field, class:"input-default" %><br /> 36 <%= f.text_field :special_field, class:"input-default", autocomplete: "special_field" %> 37 </div> 38 39 <div class="field"> 40 <%= f.label :message, class:"input-default" %><br /> 41 <%= f.text_area :message, class:"input-default", autocomplete: "special_field" %> 42 </div> 43 44 <div class="actions"> 45 <%= f.submit "Sign up" %> 46 </div> 47<% end %> 48</div>
users/registrations/new.html.erb
ruby
1<div class="new-maim"> 2<%= form_with model: @user, url: user_registration_path, class: 'registration-main', local: true do |f| %> 3 <%= render "devise/shared/error_messages", resource: resource %> 4 <h2>Sign up</h2> 5 <div class="field"> 6 <%= f.label :nickname, class:"title-default" %><br /> 7 <%= f.text_field :nickname, class:"input-default", autofocus: true, autocomplete: "nickname" %> 8 </div> 9 10 11 <div class="field"> 12 <%= f.label :email, class:"title-default" %><br /> 13 <%= f.email_field :email, class:"input-default", autofocus: true, autocomplete: "email" %> 14 </div> 15 16 <div class="field"> 17 <%= f.label :password, class:"title-default" %> 18 <% if @minimum_password_length %> 19 <em>(<%= @minimum_password_length %> characters minimum)</em> 20 <% end %><br /> 21 <%= f.password_field :password, class:"input-default", autocomplete: "new-password" %> 22 </div> 23 24 <div class="field"> 25 <%= f.label :password_confirmation, class:"title-default" %><br /> 26 <%= f.password_field :password_confirmation, class:"input-default", autocomplete: "new-password" %> 27 </div> 28 29 <div class="field"> 30 <%= f.label :gender, class:"title-default"%> 31 <%= f.collection_select(:gender_id, Gender.all, :id, :name, {prompt: "--------"}, {class:"input-default-pull"}) %> 32 <%= f.label :bloodtype, class:"title-default" %> 33 <%= f.collection_select(:bloodtype_id, Bloodtype.all, :id, :name, {prompt: "--------"}, {class:"input-default-pull"}) %> 34 </div> 35 36 <div class="field"> 37 <%= f.label :birth, class:"title-default" %><br /> 38 <%= f.password_field :birth, class:"input-default", autocomplete: "birth" %> 39 </div> 40 41 <div class="field"> 42 <%= f.label :emergencyperson, class:"title-default" %><br /> 43 <%= f.password_field :emergencyperson, class:"input-default", autocomplete: "emergencyperson" %> 44 </div> 45 46 <div class="field"> 47 <%= f.label :emergencycall, class:"title-default"%><br /> 48 <%= f.password_field :emergencycall, class:"input-default", autocomplete: "emergencycall" %> 49 </div> 50 51 <div class="btn-field"> 52 <%= f.submit "Sign up", class:"input-default" %> 53 </div> 54<% end %> 55<%= render "devise/shared/links" %> 56</div> 57
doctors/index.html.erb
<div class="doctor-access"> <div class="user-nav"> <%= image_tag "doctor.jpg", class:"main-pict" %> <% if user_signed_in? %> <div class="user_nav grid-6"> <%= link_to "ログアウト", destroy_doctor_session_path, method: :delete %> <%= link_to "投稿する", destroy_doctor_session_path, class: "post" %> </div> <% else %> <div class="btn-icon-nav"> <%= link_to new_doctor_session_path do %> <div class="btn-icon"> <p>ログイン</p> </div> <% end %> <%= link_to new_doctor_registration_path do %> <div class="btn-icon"> <p>新規会員登録</p> </div> <% end %> </div>
ruby
1class DoctorsController < ApplicationController 2 def index 3 end 4 5 def new 6 @doctor = Doctor.new 7 end 8 9 def create 10 @doctor = Doctor.new(doctor_params) 11 if @doctor.save 12 redirect_to doctor_path 13 else 14 render 'new' 15 end 16 17 def show 18 @doctorr = Doctor.find([:id]) 19 20 end 21 22 end 23 24 25 private 26 def doctor_params 27 params.require(:doctor).permit(:doctor_name, :email, :password) 28 end 29end 30
たくさんのコードになってしまいすみません。。。
回答1件
あなたの回答
tips
プレビュー