【发布时间】:2017-06-27 15:49:51
【问题描述】:
从我的 Rails 应用程序中注销会在日志中生成 Completed 204 No Content 错误。视图会冻结,直到手动刷新。
我已将错误跟踪到处理 DELETE 请求的方式:
Started DELETE "/users/sign_out" for 127.0.0.1 at 2017-02-09 06:55:24 -0800
Processing by Devise::SessionsController#destroy as */*
第二行应该有HTML 而不是*/*。关于我需要更改什么配置来解决这个问题的任何提示?
更新 这是一个使用 Rails 后端和 Hyperloop 项目中的 HyperReact 模块的测试应用程序。所以视图被渲染为一个 React 组件。这是该组件的代码:
module Components
module Users
class Show < React::Component::Base
param :name, type: String
param :provider, type: String
param :signed_in_at, type: String
param :ip, type: String
param :avatar, type: String
def render
div do
img(src: params.avatar, width: 50, height: 50)
h1 { "Hello and welcome to your profile page #{params.name}!"}
h2 { "You are signed in with #{params.provider} since #{params.signed_in_at}." }
h3 { "Your ip is #{params.ip}." }
button.btn.btn_default(type: :button) { "Signout!" }.on(:click) do
HTTP.delete("users/sign_out")
alert("Signing out")
end
end
end
end
end
end
【问题讨论】:
-
您能发布您的退出方式吗?您正在使用的链接/按钮的代码?从外观上看,这是您的问题。
-
@Mark 已更新退出代码。
-
代码好像没问题,你定义了root_path吗?设计将其用于交互后的基本重定向,因为说“无内容”我猜它没有去哪里,如果还有另一个问题,你总是可以覆盖 after_sign_out_path 方法(或类似的东西,不确定名称,但在设计 wiki 中)
-
在 routes.rb 中 root 设置为
users#show但 users_controller 在顶部有一个before_action :authenticate_user!。如果没有经过身份验证,它应该使用 Devise users::sessions 控制器,对吧?
标签: ruby-on-rails devise logout