[Ruby on Rails] Overriding Devise's current_user method

Tadashi Shigeoka ·  Thu, December 6, 2012

Notes on how to override Devise’s current_user method in Ruby on Rails.

When you want to always get the user’s Role together, write it like this:

# app/controllers/application_controller.rb 
class ApplicationController < ActionController::Base
  alias_method :devise_current_user, :current_user
  def current_user
    if devise_current_user.nil?
      nil
    else
      User.find_by_id(devise_current_user.id, include: :role)
    end
  end
end

【Reference】ruby on rails 3 - Where to override current_user helper method of devise gem - Stack Overflow

That’s all from the Gemba.