Cache Ruby Variables

Get user from the database only if @current_user does not already exist.

class ApplicationController
    @current_user ||= User.find(session[:user_id])
end

Performance improvement ensues.

Categories

ruby
performance

Comments