ruby on rails - How can I conserve hits to the database -


i'm not sure if every call current_brain.current_vocab_badge, there separate call database.

if have :

  max_prog             = (current_brain.current_vocab_badge.topic.words.count * 2)   comp_prog            = current_brain.current_vocab_badge.questions.where('style != ?', 'visualprereq').select{|q| q.weakness.blank? }.size   { totes_left: remaining_prog, totes_so_far: comp_prog, cur_badge: current_brain.current_vocab_badge.name } 

would making 3 separate calls database current_brain.current_vocab_badge current_brain instantiated in application_controller :

def current_brain   current_user.brain end 

if make instance variable of , refer variable, or application_controller achieving that?

this help

def current_brain   @current_brain ||= current_user.brain end 

Comments