2012-09-14 85 views
0

在rails中,如果我爲表「用戶」使用設計,它會創建一個在整個代碼中使用的全局變量current_user。我想添加一個類似的全局變量(current_auth_user)而不用觸及設計代碼。什麼是最好的方式來做到這一點?全局變量類似於設計中的軌道

回答

3

在你的應用程序控制器,你可以只添加一個輔助方法

class ApplicationController < ActionController::Base 
    helper_method :current_auth_user 

    protected 

    def current_auth_user 
    return whatever 
    end 

end