ruby-on-rails - 使用用户名经过身份验证的设计根
问题描述
如果用户使用 Devise 登录,我想将他们重定向到他们的帖子索引。
/username/posts
根据设计文档
,我可以使用一个authenticated
块。
authenticated :user do
....
end
但我需要用户的用户名重定向到那里。像这样的东西。
authenticated :user do |user|
get '/', to: user_posts(user)
end
但这不受支持。
如何将当前用户重定向到经过身份验证的根?
编辑:
不要试图做一个after sign in
设计路径。尝试为已登录用户和已注销用户实现永久 root。
解决方案
试试看:
class ApplicationController < ActionController::Base
def after_sign_in_path_for(user)
user_posts_url(user)
end
end
推荐阅读
- python-3.x - Keras 中的多个参数化指标
- android - 从 Android 应用程序开发的角度来看,启用对 Samsung DeX 和 Chrome OS 的支持有什么区别?
- reactjs - 使用 i18next-browser-languagedetector 为 reactJs Web 应用程序检测浏览器的语言
- java - java - 关闭单击带有硒的firefox窗口的X时关闭geckodriver?
- java - 我应该将没有任何实现的接口移动到库中吗
- widget - Instagram Widget Sizing - 图片大小不同
- ios - 无法从 UITextField 中删除所有字符
- regex - 删除所有内容的正则表达式,除了其中包含特定字符串的任何标签
- r - 观星者 html 回归表中未显示 P 值显着性
- c# - Visual Studio C# - 控制台输出不正确的字符串