如何让设计不需要主页认证?
How to make devise not require authentication for home page?
我在应用程序控制器中有 before_action :authenticate_user!
,这非常有效,因为它适用于所有控制器,但有一个页面(主页)无需登录即可使用。
有没有办法将 before_action :authenticate_user!
保留在 application_controller.rb
中(为了 DRY)并破例允许仅访问 home#home
无需身份验证?
备注:
- 我们显然可以从应用程序控制器中删除
before_action :authenticate_user!
并将其放置在所有控制器中 但是 用于 'home#home'
(缺点是它不是很干)
- 只是一个旁注,但我不确定为什么
/users/sign_in
url 甚至可以访问(设计中的某些东西必须如此,但我不确定那个机制在哪里生活或它到底是什么 - 也许如果我找到它我可以添加更多路线?)
您想使用 skip_before_action
跳过 before_action
在该页面的控制器中放置
skip_before_action :authenticate_user!, only: [:home]
这仅针对该操作指定它,如果需要跳过该控制器中的所有页面,您可以使用
skip_before_action :authenticate_user!
我在应用程序控制器中有 before_action :authenticate_user!
,这非常有效,因为它适用于所有控制器,但有一个页面(主页)无需登录即可使用。
有没有办法将 before_action :authenticate_user!
保留在 application_controller.rb
中(为了 DRY)并破例允许仅访问 home#home
无需身份验证?
备注:
- 我们显然可以从应用程序控制器中删除
before_action :authenticate_user!
并将其放置在所有控制器中 但是 用于'home#home'
(缺点是它不是很干) - 只是一个旁注,但我不确定为什么
/users/sign_in
url 甚至可以访问(设计中的某些东西必须如此,但我不确定那个机制在哪里生活或它到底是什么 - 也许如果我找到它我可以添加更多路线?)
您想使用 skip_before_action
before_action
在该页面的控制器中放置
skip_before_action :authenticate_user!, only: [:home]
这仅针对该操作指定它,如果需要跳过该控制器中的所有页面,您可以使用
skip_before_action :authenticate_user!