RailsCasts中文版,#1 Caching with Instance Variables 缓存实例变量
class ApplicationController < ActionController::Base def current_user User.find(session[:user_id]) end end
@current_user ||= User.find(session[:user_id])
class ApplicationController < ActionController::Base def current_user @current_user ||= User.find(session[:user_id]) end end
作者授权:You are welcome to post the translated text on your blog as well if the episode is free(not Pro). I just ask that you post a link back to the original episode on railscasts.com.
原文链接:http://railscasts.com/episodes/1-caching-with-instance-variables