Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有几种私有方法用于对应用程序中的所有页面进行身份验证。私有方法的整个想法是不让其他类调用它,因此集中化似乎违背了目的。然而,随着我越来越习惯“红宝石方式”,重复自己变得越来越烦人。
有没有办法在不侵犯方法隐私的情况下实现 DRY 代码?
谢谢。
使其在您的 ApplicationController 或您正在使用的所有经过身份验证的控制器扩展的任何其他“基本”控制器中受到保护。