From ea5f89e55c7afde4bf2d6719b0afa8a878082fb5 Mon Sep 17 00:00:00 2001 From: elijah Date: Tue, 12 Feb 2013 23:46:35 -0800 Subject: misc fixes to get working in production mode using Thin. --- app/controllers/application_controller.rb | 22 ++++++++++++---------- app/helpers/navigation_helper.rb | 3 ++- 2 files changed, 14 insertions(+), 11 deletions(-) (limited to 'app') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b2c5762..b73a463 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -22,18 +22,20 @@ class ApplicationController < ActionController::Base # ensure that the locale is encoded as the url prefix and I18n.locale is set. # def set_locale - if params[:locale].nil? || !AVAILABLE_LANGUAGES.include?(params[:locale]) - locale = HttpAcceptLanguage::compatible_language_from(request.headers['HTTP_ACCEPT_LANGUAGE'], AVAILABLE_LANGUAGES) || DEFAULT_LOCALE - locale = locale.to_s.sub('-', '_').sub(/_\w\w/, '') - if request.path == '/' - url = '/' + locale + if request.format == 'text/html' + if params[:locale].nil? || !AVAILABLE_LANGUAGES.include?(params[:locale]) + locale = HttpAcceptLanguage::compatible_language_from(request.headers['HTTP_ACCEPT_LANGUAGE'], AVAILABLE_LANGUAGES) || DEFAULT_LOCALE + locale = locale.to_s.sub('-', '_').sub(/_\w\w/, '') + if request.path == '/' + url = '/' + locale + else + url = url_for(params.merge(:locale => locale)) + end + redirect_to url else - url = url_for(params.merge(:locale => locale)) + I18n.locale = params[:locale] + self.default_url_options[:locale] = params[:locale] end - redirect_to url - else - I18n.locale = params[:locale] - self.default_url_options[:locale] = params[:locale] end end diff --git a/app/helpers/navigation_helper.rb b/app/helpers/navigation_helper.rb index a43eecd..fde6b45 100644 --- a/app/helpers/navigation_helper.rb +++ b/app/helpers/navigation_helper.rb @@ -1,7 +1,7 @@ module NavigationHelper def has_side_column? - if root_page? + if root_page? || site.menu.nil? return false end second_level_children_count = site.menu.submenu(current_page_path.first).try(:size) @@ -13,6 +13,7 @@ module NavigationHelper end def top_level_navigation_links + return unless site.menu haml do first = 'first' site.menu.each do |item| -- cgit v1.2.3