ruby-on-rails - 用户使用设计更新后的几次重定向
问题描述
我正在尝试使用应该像社交网络一样运作的设计创建一个 rails 5 应用程序,因此每个用户都有一个配置文件。更新用户而不是返回配置文件后,服务器重定向到本地主机,然后有一条消息Filter chain halted as :require_no_authentication rendered or redirected
,然后才加载用户配置文件。同样在个人资料上显示一条消息“您已经登录”。我的目标是清除这些重定向。
- 我试图在自定义中更改重定向,
RegistrationController
但它说重定向太多,所以我不能只替换它。 - 我试图为经过身份验证和未经身份验证的用户设置不同的根,
routes.rb
但它并没有改变行为 - 我试图落后,
:require no authentication
但实际上我不太确定我是否正确理解它,它也没有改变任何东西。 after_sign_in_path_for
设置为用户配置文件
这是服务器输出:
Started PUT "/users" for 127.0.0.1 at 2019-06-04 12:13:37 +0200
Processing by Users::RegistrationsController#update as HTML
Parameters: {"email"=>"asdf@asdf.de", "password"=>"[FILTERED]", "password_confirmat
ion"=>"[FILTERED]", "current_password"=>"[FILTERED]"}, "commit"=>"Update"}
User Load (0.8ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 ORDER BY `users`.`id` ASC LIMIT 1
User Load (0.6ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT
1
(0.3ms) BEGIN
(0.4ms) COMMIT
Redirected to http://localhost:3000/
Completed 302 Found in 295ms (ActiveRecord: 2.1ms)
Started GET "/" for 127.0.0.1 at 2019-06-04 12:13:37 +0200
Processing by Users::SessionsController#new as HTML
User Load (0.7ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 ORDER
BY `users`.`id` ASC LIMIT 1
Redirected to http://localhost:3000/users/1
Filter chain halted as :require_no_authentication rendered or redirected
Completed 302 Found in 15ms (ActiveRecord: 0.7ms)
Started GET "/users/1" for 127.0.0.1 at 2019-06-04 12:13:37 +0200
Processing by UsersController#show as HTML
Parameters: {"id"=>"1"}
User Load (0.6ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 ORDER
BY `users`.`id` ASC LIMIT 1
User Load (0.5ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT
1
Rendering users/show.html.erb within layouts/application
Rendered users/show.html.erb within layouts/application (1.1ms)
Rendered shared/_navbar.html.erb (0.7ms)
Completed 200 OK in 162ms (Views: 145.3ms | ActiveRecord: 1.1ms)
另外,为什么用户在更新后再次登录?这是正确的行为吗?我似乎无法理解重定向到本地主机的发生和干预的位置。任何帮助,将不胜感激。
编辑 1
所以,澄清一下。我尝试使用 anauthenticated_root
但后来我得到了 errormessage Couldn't find User without an ID
。
devise_scope :user do
authenticated :user do
root to: 'users#show', as: :authenticated_root
end
root to: 'users/sessions#new'
end
此外,我无法将重定向从 root 更改为用户配置文件。所以RegistrationController
是不变的。我想在更新方法或其他地方说“更新后转到用户配置文件”。
解决方案
看起来你root_path
是/users/sign_in
,当用户更新他的帐户时,你将他重定向到根目录......但用户已经登录,所以他无法访问new_user_session_pah
. 在 Devise 中配置的后备默认位置是用户的配置文件,因此他被重定向到此路由。
您是否配置了经过身份验证的根? https://github.com/plataformatec/devise/wiki/How-To:-Define-a-different-root-route-for-logged-in-out-users
它应该可以解决您的问题(:
推荐阅读
- javascript - React-Redux 操作未生效
- flutter - Android Studio 没有在项目窗格的“Android View”中加载我的 Flutter 项目
- r - 如何在 R 中的 Fisher 测试之前正确合并两个文件并计算值?
- cxf - 将 org.apache.cxf 从 3.0.7 更新到 3.3.10 后自定义异常返回 MashallingError
- python - 如果 user_num2 大于 8,则将 user_num2 赋值为 5。 print "user_num2 is less than or equal to 8."
- kubernetes - 拥有大量 Istio 网关的影响
- python - 如何使用类执行程序?
- android - Android Studio 错误:考虑删除 _JAVA_OPTIONS
- java - 有没有办法在 elasticsearch 客户端库中检索 HTTP 代码?
- workbox - 从本地使用 WorkBox 时将“导入”转换为“常量”