Skip to content

Instantly share code, notes, and snippets.

@rubytastic
Created October 5, 2011 17:11
Show Gist options
  • Save rubytastic/1265040 to your computer and use it in GitHub Desktop.
Save rubytastic/1265040 to your computer and use it in GitHub Desktop.
class ApplicationController < ActionController::Base
protect_from_forgery
before_filter :check_beta
before_filter :set_locale
def check_beta
if APP_CONFIG['beta'] = true
render :layout => "beta"
end
end
def set_locale
I18n.locale = extract_locale_from_tld || I18n.default_locale
end
# Get locale from top-level domain or return nil if such locale is not available
# You have to put something like:
# 127.0.0.1 application.com
# 127.0.0.1 application.it
# 127.0.0.1 application.pl
# in your /etc/hosts file to try this out locally
def extract_locale_from_tld
parsed_locale = request.host.split('.').last
I18n.available_locales.include?(parsed_locale.to_sym) ? parsed_locale : nil
end
layout "application"
def sub_layout
"application"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment