开发者

devise and current_user

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜