neimad
neimad

Reputation: 229

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.

Upvotes: 0

Views: 4227

Answers (2)

Ultrasaurus
Ultrasaurus

Reputation: 3169

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

Upvotes: 2

Cydonia7
Cydonia7

Reputation: 3826

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

Upvotes: 2

Related Questions