From cb2c6b5ec372e4aa0eee18d7259f43e2239a9244 Mon Sep 17 00:00:00 2001 From: elijah Date: Sat, 25 Aug 2012 17:10:16 -0700 Subject: fixed run_once. should now be much faster :) --- app/controllers/application_controller.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 62a4e13..240df61 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,7 +3,7 @@ class ApplicationController < ActionController::Base protect_from_forgery before_filter :set_locale, :initialize_pages - if Rails.env == 'production' + if Rails.env.production? rescue_from Exception, :with => :render_500 rescue_from ActionController::RoutingError, :with => :render_404 end @@ -72,17 +72,18 @@ class ApplicationController < ActionController::Base # run every time in development mode, run once in production mode # def initialize_pages - run_once(:unless => Rails.env.development?) do + run_once(:initialize_pages, :unless => Rails.env.development?) do StaticPage.load(PAGE_DIRECTORY) Menu.load(PAGE_DIRECTORY + '/menu.txt') end end - def run_once(options={}) - if !@run_once || !options[:unless] + def run_once(name, options={}) + key_name = "run_once_#{name}" + if !Thread.current[key_name] || options[:unless] yield end - @run_once = true + Thread.current[key_name] = true end end -- cgit v1.2.3