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.
在 Rails 中,如果我将设计用于表“用户”,它会创建一个全局变量 current_user,该变量在整个代码中都使用。我想在不触及设计代码的情况下添加一个类似的全局变量(current_auth_user)。最好的方法是什么?
在您的应用程序控制器中,您只需添加一个辅助方法
class ApplicationController < ActionController::Base helper_method :current_auth_user protected def current_auth_user return whatever end end