お世話になっております。
既存アプリにDeviseでユーザー認証機能を実装中です。Deviseでフォームから新規登録ができない現象を解決できずにいます。
ご助言いただけると幸いです。
不具合内容
SubmitしてもPOSTにならず、GETが送信されてしまうためアカウント登録画面が再度表示されてしまいます。
console
1Started GET "/users/sign_up" for ::1 at 2022-04-02 12:36:22 +0900 2Processing by Devise::RegistrationsController#new as HTML 3 Rendering layout layouts/application.html.erb 4 Rendering devise/registrations/new.html.erb within layouts/application 5 Rendered devise/shared/_error_messages.html.erb (Duration: 1.7ms | Allocations: 242) 6 Rendered devise/registrations/new.html.erb within layouts/application (Duration: 8.5ms | Allocations: 1825) 7[Webpacker] Everything's up-to-date. Nothing to do 8 Rendered layouts/_shim.html.erb (Duration: 0.2ms | Allocations: 40) 9 Rendered layouts/_header.html.erb (Duration: 1.0ms | Allocations: 125) 10 Rendered layouts/_sidebar.html.erb (Duration: 0.5ms | Allocations: 52) 11 Rendered layouts/_footer.html.erb (Duration: 0.2ms | Allocations: 40) 12 Rendered layout layouts/application.html.erb (Duration: 49.9ms | Allocations: 14432) 13Completed 200 OK in 63ms (Views: 59.2ms | ActiveRecord: 0.0ms | Allocations: 16257)
前提事項
・macOS Monterey v12.1
・ruby v3.0.3
・Rails v6.1.4.4
・devise 4.8.1
その他
・自作ユーザー認証機能のdeviseへの置き換え
・Divise用のコントローラとViewを作成済み
・コンソールからのユーザー登録は正常に動作
・logにはデータベースと通信した形跡は無し(次項参照)
関係するコード
ルーティング
config/routes.rb
1 devise_for :users, controllers: { 2 registrations: 'users/registrations', 3 sessions: 'users/sessions', 4 passwords: 'users/passwords', 5 confirmations: 'users/confirmations' 6 } 7 8 devise_scope :user do 9 root "devise/sessions#new" 10 end 11...
console
1$ rails routes 2 3 new_user_session GET /users/sign_in(.:format) users/sessions#new 4 user_session POST /users/sign_in(.:format) users/sessions#create 5 destroy_user_session DELETE /users/sign_out(.:format) users/sessions#destroy 6 new_user_password GET /users/password/new(.:format) users/passwords#new 7 edit_user_password GET /users/password/edit(.:format) users/passwords#edit 8 user_password PATCH /users/password(.:format) users/passwords#update 9 PUT /users/password(.:format) users/passwords#update 10 POST /users/password(.:format) users/passwords#create 11 cancel_user_registration GET /users/cancel(.:format) users/registrations#cancel 12 new_user_registration GET /users/sign_up(.:format) users/registrations#new 13 edit_user_registration GET /users/edit(.:format) users/registrations#edit 14 user_registration PATCH /users(.:format) users/registrations#update 15 PUT /users(.:format) users/registrations#update 16 DELETE /users(.:format) users/registrations#destroy 17 POST /users(.:format) users/registrations#create 18 root GET / devise/sessions#new
コントローラー
app/controllers/users/registrations_controller.rb
1class Users::RegistrationsController < Devise::RegistrationsController 2 # before_action :configure_sign_up_params, only: [:create] 3 # before_action :configure_account_update_params, only: [:update] 4 5 # GET /resource/sign_up 6 # def new 7 # super 8 # end 9 10 # POST /resource 11 # def create 12 # super 13 # end 14 15 # GET /resource/edit 16 # def edit 17 # super 18 # end 19 20 # PUT /resource 21 # def update 22 # super 23 # end 24 25 # DELETE /resource 26 # def destroy 27 # super 28 # end 29 30 # GET /resource/cancel 31 # Forces the session data which is usually expired after sign 32 # in to be expired now. This is useful if the user wants to 33 # cancel oauth signing in/up in the middle of the process, 34 # removing all OAuth session data. 35 # def cancel 36 # super 37 # end 38 39 # protected 40 41 # If you have extra params to permit, append them to the sanitizer. 42 # def configure_sign_up_params 43 # devise_parameter_sanitizer.permit(:sign_up, keys: [:email, :encrypted_password]) 44 # end 45 46 # If you have extra params to permit, append them to the sanitizer. 47 # def configure_account_update_params 48 # devise_parameter_sanitizer.permit(:account_update, keys: [:email, :encrypted_password]) 49 # end 50 51 # The path used after sign up. 52 def after_sign_up_path_for(resource) 53 user_url(resource) 54 end 55 56 # The path used after sign up for inactive accounts. 57 def after_inactive_sign_up_path_for(resource) 58 new_user_session_url 59 end 60end
###ビュー
app/views/devise/registrations/new.html.erb
1<% provide(:title, 'アカウント登録') %> 2<% provide(:button_text, '認証メールを送信する') %> 3 4 <div class="bg-white py-6 sm:py-8 lg:py-12"> 5 <div class="max-w-screen-2xl px-4 md:px-8 mx-auto"> 6 <h2 class="text-gray-800 text-2xl lg:text-3xl font-bold text-center mb-4 md:mb-8">アカウント登録</h2> 7 <form class="max-w-lg border rounded-lg mx-auto"> 8 <div class="flex flex-col gap-4 p-4 md:p-8"> 9 <%= form_with model: @user, url: user_registration_path, id: 'new_user', class: 'new_user', local: true do |f| %> 10 <%= render "devise/shared/error_messages", resource: @user %> 11 <div> 12 <%= f.label :name, "アカウント名", class: 'inline-block text-gray-800 text-sm sm:text-base mb-2' %> 13 <%= f.text_field :name, autofocus: true, autocomplete: "name", class: 'w-full bg-gray-50 text-gray-800 border focus:ring ring-indigo-300 rounded outline-none transition duration-100 px-3 py-2' %> 14 </div> 15 <div> 16 <%= f.label :email, "メールアドレス", class: 'inline-block text-gray-800 text-sm sm:text-base mb-2' %> 17 <%= f.email_field :email, autofocus: true, autocomplete: "email", class: 'w-full bg-gray-50 text-gray-800 border focus:ring ring-indigo-300 rounded outline-none transition duration-100 px-3 py-2' %> 18 </div> 19 <div> 20 <%= f.label :password, "パスワード", class: 'inline-block text-gray-800 text-sm sm:text-base mb-2' %> 21 <% if @minimum_password_length %> 22 <em>(<%= @minimum_password_length %> characters minimum)</em> 23 <% end %><br /> 24 <%= f.password_field :password, autocomplete: "new-password", class: 'w-full bg-gray-50 text-gray-800 border focus:ring ring-indigo-300 rounded outline-none transition duration-100 px-3 py-2' %> 25 </div> 26 <div> 27 <%= f.label :password_confirmation, "パスワード(確認)", class: 'inline-block text-gray-800 text-sm sm:text-base mb-2' %> 28 <%= f.password_field :password_confirmation, autocomplete: "new-password", class: 'w-full bg-gray-50 text-gray-800 border focus:ring ring-indigo-300 rounded outline-none transition duration-100 px-3 py-2' %> 29 </div> 30 <!-- 認証メール送信ボタン --> 31 <%= f.submit yield(:button_text), class: "block bg-gray-800 hover:bg-gray-700 active:bg-gray-600 focus-visible:ring ring-gray-300 text-white text-sm md:text-base font-semibold text-center rounded-lg outline-none transition duration-100 px-8 py-3" %> 32 <% end %> 33 </div> 34 <!-- ナビゲーション --> 35 <div class="flex justify-center items-center p-4 "> 36 <%= link_to "アカウントをお持ちの方はこちら", new_user_session_path, class: "text-indigo-500 hover:text-indigo-600 active:text-indigo-700 transition duration-100" %> 37 </div> 38 </form> 39 </div> 40</div>
何か、考えられる原因はありますでしょうか。
よろしくお願いします。

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。