結論、form_with
にlocal: true
を設定していない!
パスワードリセット機能実装中、パスワードの変更処理はできているものの、ログインページへredirectされず、フラッシュメッセージも表示されない現象に陥りました。
<password_resets/edit.html.erb>
<%= form_with model: @user, url: password_reset_path(@token), method: :put do |f| %>
<password_resets_controller.rb>
def update
@token = params[:id]
@user = User.load_from_reset_password_token(params[:id])
if @user.blank?
not_authenticated
return
end
@user.password_confirmation = params[:user][:password_confirmation]
if @user.change_password(params[:user][:password])
redirect_to(login_path, success: 'パスワードを変更しました') #redirectされない、ぴえん。
else
flash.now[:danger] = 'パスワードの変更に失敗しました'
render :action => "edit"
end
end
form_with
にlocal: true
を追加したところredirectされるようになりました!
<password_resets/edit.html.erb>
<%= form_with model: @user, url: password_reset_path(@token),**local: true**, method: :put do |f| %>