我创建了一个rails 5 api项目并使用
Devise gem 4.1.0
Ruby 2.3.0
Rails 5.0.0.rc1
我运行命令来覆盖SessionsController
rails generate devise:controllers users
我的自定义会话控制器是
class Users::SessionsController < Devise::SessionsController
# before_action :configure_sign_in_params, only: [:create]
# GET /resource/sign_in
# def new
# super
# end
# POST /resource/sign_in
def create
super
end
# DELETE /resource/sign_out
def destroy
super
end
# protected
# If you have extra params to permit, append them to the sanitizer.
# def configure_sign_in_params
# devise_parameter_sanitizer.permit(:sign_in, keys: [:attribute])
# end
end
调用路径到sign_out 时出错
127.0.0.1:3000/users/sign_out
错误为
"status": 500,
"error": "Internal Server Error",
"exception": "#<NameError: undefined local variable or method `flash' for #<Users::SessionsController:0x00000003d2e8f0>>",
"traces": {
"Application Trace": [],
"Framework Trace": [
{
"id": 0,
"trace": "devise (4.1.1) app/controllers/devise_controller.rb:157:in `set_flash_message'"
},
{
"id": 1,
"trace": "devise (4.1.1) app/controllers/devise_controller.rb:164:in `set_flash_message!'"
},
{
"id": 2,
"trace": "devise (4.1.1) app/controller
s/design/sessions_controller.rb:61:in `verify_signed_out_user'"},
我在routes.rb 中的当前路线
devise_for :users,
controllers: {
sessions: 'users/sessions',
registrations: 'users/registrations'
}
我进行了调试,但路径没有路由到app/controller/users/SessionsController我如何路由该路径
需要更改销毁以执行获取请求
转到config/enitializers/device.rb,在239行更改
config.sign_out_via = :delete
至
config.sign_out_via = :get