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 ++++++----- app/views/pages/about-us/news/2012/first-post/en.haml | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'app') 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 diff --git a/app/views/pages/about-us/news/2012/first-post/en.haml b/app/views/pages/about-us/news/2012/first-post/en.haml index d32753a..164092c 100644 --- a/app/views/pages/about-us/news/2012/first-post/en.haml +++ b/app/views/pages/about-us/news/2012/first-post/en.haml @@ -1,4 +1,4 @@ -- @title = "Tada! A website" +- @title = "Tada! A website." - @author = "Elijah" - @posted_at = "2012-08-24" - @tags = [''] -- cgit v1.2.3