Browse files

Create a Controller and Views to Display Subdomain Sites

  • Loading branch information...
1 parent 1076bcb commit 89f82489302a7e654406e5583c0dabcbcaf22314 @fortuity committed Aug 8, 2010
View
6 app/controllers/sites_controller.rb
@@ -0,0 +1,6 @@
+class SitesController < ApplicationController
+ def show
+ @site = Site.find_by_name!(request.subdomain)
+ end
+
+end
View
2 app/helpers/sites_helper.rb
@@ -0,0 +1,2 @@
+module SitesHelper
+end
View
2 app/views/sites/show.html.erb
@@ -0,0 +1,2 @@
+<h1>Site: <%= @site.name %></h1>
+<p>Belongs to: <%= link_to @site.user.name, user_url(@site.user) %></p>
View
1 config/routes.rb
@@ -3,6 +3,7 @@
resources :users, :only => [:index, :show] do
resources :subdomains, :shallow => true
end
+ match '/' => 'sites#show', :constraints => { :subdomain => /.+/ }
root :to => "home#index"
# The priority is based upon order of creation:
View
9 test/functional/sites_controller_test.rb
@@ -0,0 +1,9 @@
+require 'test_helper'
+
+class SitesControllerTest < ActionController::TestCase
+ test "should get show" do
+ get :show
+ assert_response :success
+ end
+
+end
View
4 test/unit/helpers/sites_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class SitesHelperTest < ActionView::TestCase
+end

0 comments on commit 89f8248

Please sign in to comment.