お世話になっております。
既存アプリにDeviseでユーザー認証機能を実装中です。Deviseでフォームから新規登録ができない現象を解決できずにいます。
ご助言いただけると幸いです。
不具合内容
SubmitしてもPOSTにならず、GETが送信されてしまうためアカウント登録画面が再度表示されてしまいます。
console
Started GET "/users/sign_up" for ::1 at 2022-04-02 12:36:22 +0900 Processing by Devise::RegistrationsController#new as HTML Rendering layout layouts/application.html.erb Rendering devise/registrations/new.html.erb within layouts/application Rendered devise/shared/_error_messages.html.erb (Duration: 1.7ms | Allocations: 242) Rendered devise/registrations/new.html.erb within layouts/application (Duration: 8.5ms | Allocations: 1825) [Webpacker] Everything's up-to-date. Nothing to do Rendered layouts/_shim.html.erb (Duration: 0.2ms | Allocations: 40) Rendered layouts/_header.html.erb (Duration: 1.0ms | Allocations: 125) Rendered layouts/_sidebar.html.erb (Duration: 0.5ms | Allocations: 52) Rendered layouts/_footer.html.erb (Duration: 0.2ms | Allocations: 40) Rendered layout layouts/application.html.erb (Duration: 49.9ms | Allocations: 14432) Completed 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
devise_for :users, controllers: { registrations: 'users/registrations', sessions: 'users/sessions', passwords: 'users/passwords', confirmations: 'users/confirmations' } devise_scope :user do root "devise/sessions#new" end ...
console
$ rails routes new_user_session GET /users/sign_in(.:format) users/sessions#new user_session POST /users/sign_in(.:format) users/sessions#create destroy_user_session DELETE /users/sign_out(.:format) users/sessions#destroy new_user_password GET /users/password/new(.:format) users/passwords#new edit_user_password GET /users/password/edit(.:format) users/passwords#edit user_password PATCH /users/password(.:format) users/passwords#update PUT /users/password(.:format) users/passwords#update POST /users/password(.:format) users/passwords#create cancel_user_registration GET /users/cancel(.:format) users/registrations#cancel new_user_registration GET /users/sign_up(.:format) users/registrations#new edit_user_registration GET /users/edit(.:format) users/registrations#edit user_registration PATCH /users(.:format) users/registrations#update PUT /users(.:format) users/registrations#update DELETE /users(.:format) users/registrations#destroy POST /users(.:format) users/registrations#create root GET / devise/sessions#new
コントローラー
app/controllers/users/registrations_controller.rb
class Users::RegistrationsController < Devise::RegistrationsController # before_action :configure_sign_up_params, only: [:create] # before_action :configure_account_update_params, only: [:update] # GET /resource/sign_up # def new # super # end # POST /resource # def create # super # end # GET /resource/edit # def edit # super # end # PUT /resource # def update # super # end # DELETE /resource # def destroy # super # end # GET /resource/cancel # Forces the session data which is usually expired after sign # in to be expired now. This is useful if the user wants to # cancel oauth signing in/up in the middle of the process, # removing all OAuth session data. # def cancel # super # end # protected # If you have extra params to permit, append them to the sanitizer. # def configure_sign_up_params # devise_parameter_sanitizer.permit(:sign_up, keys: [:email, :encrypted_password]) # end # If you have extra params to permit, append them to the sanitizer. # def configure_account_update_params # devise_parameter_sanitizer.permit(:account_update, keys: [:email, :encrypted_password]) # end # The path used after sign up. def after_sign_up_path_for(resource) user_url(resource) end # The path used after sign up for inactive accounts. def after_inactive_sign_up_path_for(resource) new_user_session_url end end
###ビュー
app/views/devise/registrations/new.html.erb
<% provide(:title, 'アカウント登録') %> <% provide(:button_text, '認証メールを送信する') %> <div class="bg-white py-6 sm:py-8 lg:py-12"> <div class="max-w-screen-2xl px-4 md:px-8 mx-auto"> <h2 class="text-gray-800 text-2xl lg:text-3xl font-bold text-center mb-4 md:mb-8">アカウント登録</h2> <form class="max-w-lg border rounded-lg mx-auto"> <div class="flex flex-col gap-4 p-4 md:p-8"> <%= form_with model: @user, url: user_registration_path, id: 'new_user', class: 'new_user', local: true do |f| %> <%= render "devise/shared/error_messages", resource: @user %> <div> <%= f.label :name, "アカウント名", class: 'inline-block text-gray-800 text-sm sm:text-base mb-2' %> <%= 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' %> </div> <div> <%= f.label :email, "メールアドレス", class: 'inline-block text-gray-800 text-sm sm:text-base mb-2' %> <%= 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' %> </div> <div> <%= f.label :password, "パスワード", class: 'inline-block text-gray-800 text-sm sm:text-base mb-2' %> <% if @minimum_password_length %> <em>(<%= @minimum_password_length %> characters minimum)</em> <% end %><br /> <%= 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' %> </div> <div> <%= f.label :password_confirmation, "パスワード(確認)", class: 'inline-block text-gray-800 text-sm sm:text-base mb-2' %> <%= 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' %> </div> <!-- 認証メール送信ボタン --> <%= 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" %> <% end %> </div> <!-- ナビゲーション --> <div class="flex justify-center items-center p-4 "> <%= link_to "アカウントをお持ちの方はこちら", new_user_session_path, class: "text-indigo-500 hover:text-indigo-600 active:text-indigo-700 transition duration-100" %> </div> </form> </div> </div>
何か、考えられる原因はありますでしょうか。
よろしくお願いします。
まだ回答がついていません
会員登録して回答してみよう