摘要:        
Ruby 的延迟计算大家已经用得很多了, 下面就是一个范例class ApplicationController def current_user @current_user ||= User.where(:id => session[:user_id]).first endendclass FooController < ApplicationController def foo current_user current_user endend但这个范例有一个问题, 如果 current_user 不存在, 那么每次调用 current_user 时都会额外查询一次数据库, 优化    阅读全文
posted @ 2011-02-26 21:48
LI Daobing
阅读(1958)
评论(0)
推荐(0)
			
                    
                
浙公网安备 33010602011771号