summaryrefslogtreecommitdiffstats
path: root/app/controllers/application_controller.rb
diff options
context:
space:
mode:
authorJohan Sørensen <johan@johansorensen.com>2009-03-03 13:58:06 +0100
committerJohan Sørensen <johan@johansorensen.com>2009-04-22 15:15:37 +0200
commit94672a0734355ddc13bece2394f8fae79c7bb0b1 (patch)
treee5372d1c77cc65c46d84808b7fb47b51704e155d /app/controllers/application_controller.rb
parent6d3c5da512a09aed7da8c6485f109276bc6c5006 (diff)
downloadgitorious-mainline-outdated-94672a0734355ddc13bece2394f8fae79c7bb0b1.zip
gitorious-mainline-outdated-94672a0734355ddc13bece2394f8fae79c7bb0b1.tar.gz
gitorious-mainline-outdated-94672a0734355ddc13bece2394f8fae79c7bb0b1.tar.bz2
Redirect to the current_site's subdomain, if it has one and it's a GET request
Diffstat (limited to 'app/controllers/application_controller.rb')
-rw-r--r--app/controllers/application_controller.rb33
1 files changed, 27 insertions, 6 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 43a1598..d7a911e 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -23,8 +23,6 @@ class ApplicationController < ActionController::Base
include ExceptionNotifiable
before_filter :public_and_logged_in
- append_before_filter :find_current_site
- #TODO: append_before_filter :redirect_to_current_site_subdomain
layout :pick_layout_based_on_site
@@ -34,8 +32,6 @@ class ApplicationController < ActionController::Base
rescue_from Grit::GitRuby::Repository::NoSuchPath, :with => :render_not_found
rescue_from Grit::Git::GitTimeout, :with => :render_git_timeout
- attr_reader :current_site
-
def rescue_action(exception)
return super if RAILS_ENV != "production"
@@ -49,7 +45,16 @@ class ApplicationController < ActionController::Base
end
end
+ def current_site
+ @current_site || Site.default
+ end
+
protected
+ def self.install_site_before_filters
+ before_filter :find_current_site
+ before_filter :redirect_to_current_site_subdomain
+ end
+
# return the url with the +repo+.owner prefixed if it's a mainline repo,
# otherwise return the +path_spec+
# if +path_spec+ is an array (and no +args+ given) it'll use that as the
@@ -189,9 +194,9 @@ class ApplicationController < ActionController::Base
def find_current_site
@current_site ||= begin
if subdomain_without_common.blank?
- @project ? @project.site : Site.default
+ @project.site if @project
else
- Site.find_by_subdomain(subdomain_without_common) || Site.default
+ Site.find_by_subdomain(subdomain_without_common)
end
end
end
@@ -208,6 +213,22 @@ class ApplicationController < ActionController::Base
request.subdomains.select{|s| s !~ /^(ww.|secure)$/}.first
end
+ def redirect_to_current_site_subdomain
+ return unless request.get?
+ if !current_site.subdomain.blank?
+ if subdomain_without_common != current_site.subdomain
+ host_with_subdomain = {
+ :only_path => false,
+ :host => "#{current_site.subdomain}.#{request.host}"
+ }
+ if ![80, 443].include?(request.port)
+ host_with_subdomain[:host] << ":#{request.port}"
+ end
+ redirect_to host_with_subdomain
+ end
+ end
+ end
+
private
def unshifted_polymorphic_path(repo, path_spec)
if path_spec[0].is_a?(Symbol)