开发者

devise and current_user

开发者 https://www.devze.com 2023-03-28 08:40 出处:网络
i have a question about devise system. my last ruby project was done with nifty:authnentication. With nifty, i can manage session for current_user and other information from \'\"controller_authentica

i have a question about devise system.

my last ruby project was done with nifty:authnentication. With nifty, i can manage session for current_user and other information from '"controller_authentication.rb"'. But now, i want to add a new current_* information.

I want to开发者_运维百科 know where i can find current_user method? where is it defined?

with nifty i used something like

@current_company ||= Company.find(session[:company_id]) if session[:company_id]

thanks.


current_user is defined as a helper in devise source code. When you install devise on your project, it gets activated too.


current_user is defined dynamically in Devise. Since your user model could actually be a different model, the method uses your model name for 'mapping' when it defines the current_whatever helper method:

def current_#{mapping}
    @current_#{mapping} ||= warden.authenticate(:scope => :#{mapping})
end

https://github.com/plataformatec/devise/blob/master/lib/devise/controllers/helpers.rb#L123

0

精彩评论

暂无评论...
验证码 换一张
取 消