首页 > 解决方案 > 使用用户名经过身份验证的设计根

问题描述

如果用户使用 Devise 登录,我想将他们重定向到他们的帖子索引。

/username/posts

根据设计文档 ,我可以使用一个authenticated块。

authenticated :user do
   ....
end

但我需要用户的用户名重定向到那里。像这样的东西。

authenticated :user do |user|
   get '/', to: user_posts(user)
end

但这不受支持。

如何将当前用户重定向到经过身份验证的根?

编辑:

不要试图做一个after sign in设计路径。尝试为已登录用户和已注销用户实现永久 root。

标签: ruby-on-railsdevise

解决方案


试试看:

class ApplicationController < ActionController::Base
    def after_sign_in_path_for(user)
        user_posts_url(user)
    end
end

推荐阅读