如何让设计不需要主页认证?

How to make devise not require authentication for home page?

我在应用程序控制器中有 before_action :authenticate_user!,这非常有效,因为它适用于所有控制器,但有一个页面(主页)无需登录即可使用。

有没有办法将 before_action :authenticate_user! 保留在 application_controller.rb 中(为了 DRY)并破例允许仅访问 home#home 无需身份验证?

备注:

您想使用 skip_before_action

跳过 before_action

在该页面的控制器中放置

skip_before_action :authenticate_user!, only: [:home]

这仅针对该操作指定它,如果需要跳过该控制器中的所有页面,您可以使用

skip_before_action :authenticate_user!