RailsのDeviseを利用して、ユーザーのログイン機能を作っていて、困っています。
今回知りたいのは、以下の流れの⑤の部分です。
パスワードを忘れた会員ユーザーに対して
①メアドを入力してもらい
②そのメアドに対してメールを送信し(再設定画面へのリンク付き)
④再設定画面にアクセス
⑤パスワードを再設定
実装したところ、以下の問題が発生しました。
⑤の画面でのフォームのサブミットが一回しか出来ない。
(=何かの入力内容エラーで再度フォームに戻っても、サブミットボタンが押せなくなる。)
【確認済みの点】
①ブラウザのJSを無効にすると、2回目以降も問題なくサブミット出来た。
②フォーム内の =f.hidden_field :reset_password_token をコメントアウトすると、何度もでもサブミット出来た。(もちろん、controller側でtokenがないよってエラーにはなりますが、)
【環境】
Ruby:2.3.1p112
Rails:5.0.0.1
Devise:4.2.0
Turbolinks利用
view
ruby
1section.content_area 2 = form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| 3 = f.hidden_field :reset_password_token 4 5 .form_item 6 label 7 = image_tag 'icon_key.png' 8 | 新規パスワード 9 = f.password_field :password, autofocus: true, autocomplete: 'off', class: 'register_info', placeholder: '半角英数字混合で6文字以上', 'aria-required': true, size: 30 10 = error_message(resource, :password) 11 12 .form_item 13 label 14 = image_tag 'icon_key.png' 15 | 新規パスワード(確認用) 16 = f.password_field :password_confirmation, autocomplete: 'off', class: 'register_info', placeholder: 'パスワードをもう一度入力', 'aria-required': true, size: 30 17 = error_message(resource, :password_confirmation) 18 19 div 20 = f.submit 'パスワードを再設定', data: { disable_with: "変更中..." }
controller
ruby
1 # GET /resource/password/edit?reset_password_token=abcdef 2 # def edit 3 # super 4 # end 5 6 # PUT /resource/password 7 def update 8 super do |resource| 9 flash[:modal] = { name: 'update-password' } if resource.errors.empty? 10 end 11 end
userモデル
ruby
1class DeviseCreateUsers < ActiveRecord::Migration[5.0] 2 def change 3 create_table :users do |t| 4 ## Database authenticatable 5 t.string :email, null: false, default: "" 6 t.string :encrypted_password, null: false, default: "" 7 8 ## Recoverable 9 t.string :reset_password_token 10 t.datetime :reset_password_sent_at 11 12 ## Rememberable 13 t.datetime :remember_created_at 14 15 ## Trackable 16 t.integer :sign_in_count, default: 0, null: false 17 t.datetime :current_sign_in_at 18 t.datetime :last_sign_in_at 19 t.string :current_sign_in_ip 20 t.string :last_sign_in_ip 21 22 ## Confirmable 23 # t.string :confirmation_token 24 # t.datetime :confirmed_at 25 # t.datetime :confirmation_sent_at 26 # t.string :unconfirmed_email # Only if using reconfirmable 27 28 ## Lockable 29 # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts 30 # t.string :unlock_token # Only if unlock strategy is :email or :both 31 # t.datetime :locked_at 32 33 34 t.timestamps null: false 35 end 36 37 add_index :users, :email, unique: true 38 add_index :users, :reset_password_token, unique: true 39 # add_index :users, :confirmation_token, unique: true 40 # add_index :users, :unlock_token, unique: true 41 end 42end
おそらくRailsで開発して、Deviseを利用したログイン機能のあるサービスではよくあるシーンだと思うのですが、調べてもあまりそれらしい原因がわからず、教えていただけると助かります・・・・!!!
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。