Skip to content

Commit

Permalink
remove hostname from site and begin refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
saturnflyer committed Jul 18, 2010
1 parent 3945c28 commit 10194d4
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/controllers/admin/sites_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def new
def switch_to
site = Site.find(params[:id])
if site
redirect_to "http://#{site.hostname}#{request.port.to_s == '80' ? '' : ":#{request.port}"}/admin"
redirect_to "http://#{site.hostnames.first.domain}#{request.port.to_s == '80' ? '' : ":#{request.port}"}/admin"
else
render :index
end
Expand Down
4 changes: 2 additions & 2 deletions app/views/admin/sites/remove.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
%tbody
%tr.node.level-1
%td.site
= image('page', :alt => "page-icon")
= @site.hostname
= @site.title
= %{(#{@site.hostnames.map(&:domain).join(', ')})}

- form_for [:admin, @site], :html => {:method => :delete} do
%p.buttons
Expand Down
16 changes: 16 additions & 0 deletions db/migrate/20100718021117_remove_site_hostname_field.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class RemoveSiteHostnameField < ActiveRecord::Migration
def self.up
remove_column :sites, :hostname
end

def self.down
add_column :sites, :hostname, :string
Site.reset_column_information
Site.find_in_batches do |sites|
sites.each do |site|
site.hostname = site.hostnames.first.domain
site.save
end
end
end
end
2 changes: 1 addition & 1 deletion lib/vhost/admin_users_helper_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Vhost::AdminUsersHelperExtensions
def self.included(receiver)
receiver.send :alias_method_chain, :roles, :site_admin
receiver.send :define_method, :sites do |user|
sites = user.sites.collect{|site| site.hostname}
sites = user.sites.collect{|site| site.title}
sites.join("<br/>")
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/vhost/application_controller_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ def redirect_to_primary_site
if VhostExtension.REDIRECT_TO_PRIMARY_SITE
site = current_site
return if site.nil? || site.hostname.include?("*")
primary_host = site.hostname.split(',')[0].strip
primary_host = site.hostnames.first.domain
redirect_to(primary_site_url + request.request_uri) if request.host != primary_host
end
end

def primary_site_url
site = current_site
return nil if site.nil? || site.hostname.include?("*")
return nil if site.nil? || site.hostnames.map(&:domain).include?("*")

# Rebuild the current URL. Check if it matches the URL of the
# primary site and redirect if it does not.
Expand All @@ -25,7 +25,7 @@ def primary_site_url
port = request.port_string

# Primary site is the first site
primary_host = site.hostname.split(',')[0].strip
primary_host = site.hostnames.first.domain

# Return the concatenation
prefix+primary_host+port
Expand Down
2 changes: 1 addition & 1 deletion lib/vhost/application_helper_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ def self.included(receiver)
end

def subtitle_with_site_hostname
current_site.hostname
current_site.title
end
end
2 changes: 1 addition & 1 deletion spec/controllers/admin/pages_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
dataset :sites_site_users_and_site_pages

before :each do
VhostExtension.HOST = sites(:site_a).hostname # Pretend we're connected to site_a so the SiteScope works right
VhostExtension.HOST = sites(:site_a).hostnames.first.domain # Pretend we're connected to site_a so the SiteScope works right
rescue_action_in_public! # ActionController::TestCase no longer considers this request a local request

# don't bork results with stale cache items
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/site_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

before(:each) do
logout
VhostExtension.HOST = sites(:site_a).hostname # Pretend we're connected to site_a so the SiteScope works right
VhostExtension.HOST = sites(:site_a).hostnames.first.domain # Pretend we're connected to site_a so the SiteScope works right
rescue_action_in_public! # ActionController::TestCase no longer considers this request a local request

# don't bork results with stale cache items
Expand Down

0 comments on commit 10194d4

Please sign in to comment.