ruby-on-rails - 为什么“respond_with”不执行失败的设计认证?
问题描述
成功验证后,我可以这样覆盖respond_with:
class SessionsController < Devise::SessionsController
def respond_with(resource, *)
if user_signed_in?
redirect_to root_path
end
end
end
但是,当身份验证失败时——假设密码不正确——我在设计中respond_with
的覆盖SessionsController
不会被调用。我知道,对于失败的身份验证, Devise 然后调用Devise::SessionsController#new。但是,在该DeviseController#new
方法结束时respond_with
被调用。
所以我的问题是:
1) 为什么在Devise::SessionsController#create中认证成功时respond_with
我的覆盖成功执行?SessionsController
2) 为什么我在身份验证失败时对我的覆盖没有成功respond_with
执行?控制器操作以相同的方法完成SessionsController
Devise::SessionsController#create
Devise::SessionsController#new
respond_with
Devise::SessionsController#create
这是我的宝石文件:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.6.5'
gem 'rails', '~> 6.0.1'
gem 'puma', '~> 4.1'
gem 'sass-rails', '>= 6'
gem 'webpacker', '5.1.1'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.7'
gem 'bootsnap', '>= 1.4.2', require: false
gem 'haml', '~> 5.0', '>= 5.0.4'
gem 'pg', '1.2.3'
gem 'rtesseract', '3.1'
gem 'sidekiq', '6.0.6'
gem 'dotenv-rails', '2.7.5'
gem 'devise', '4.7.1'
gem 'letter_opener', '1.7.0'
group :production do
gem 'aws-sdk-s3', '1.61.2'
end
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'awesome_print'
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
# Easy installation and use of web drivers to run system tests with browsers
gem 'webdrivers'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
解决方案
推荐阅读
- android - 为什么广播接收器在重新启动时不起作用?
- python - 在 Lambda DynamoDB 函数中添加限制
- ios - IOS 14 AVPlayer 在模拟器上播放,但不在真实设备上
- elasticsearch - 弹性搜索 kubernetes 数据磁盘使用量猛增
- c# - 上传 excel 文件并在 aspnet core 中添加手动值
- mysql - MySQL CLI:未知选项:enable-cleartext-plugin
- php - 在 laravel 控制器中使用特征
- azure - Azure Kubernetes - 副本与 HPA?
- python - 在预处理文本中保持标点符号作为自己的单位
- javascript - 正则表达式:从变体搜索,但首先按变体搜索,而不是通过 searcgin 字符串