forked from fortuity/rails3-subdomain-devise
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved subdomain reference from name:string to account_id:integer, thi…
…s could pose a speed issue later on. Also created the necessary indexes.
- Loading branch information
1 parent
c2ad8d8
commit 01de78a
Showing
12 changed files
with
40 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
class SitesController < ApplicationController | ||
|
||
def index | ||
@site = Site.find_by_name(current_subdomain) | ||
@site = Site.find_by_name(current_subdomain.name) | ||
end | ||
|
||
def opps | ||
@site = Site.find_by_name(current_subdomain) | ||
@site = Site.find_by_name(current_subdomain.name) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
module ApplicationHelper | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
class User < ActiveRecord::Base | ||
belongs_to :subdomain, :primary_key => "name", :foreign_key => "subdomain_name" | ||
belongs_to :subdomain | ||
devise :database_authenticatable, :registerable, | ||
:recoverable, :rememberable, :trackable, :validatable | ||
validates_presence_of :name, :subdomain_name | ||
validates_uniqueness_of :email, :case_sensitive => false | ||
attr_accessor :subdomain_name | ||
attr_accessible :name, :subdomain_name, :email, :password, :password_confirmation, :remember_me | ||
# has_friendly_id :subdomain_name, :use_slug => true, :strip_non_ascii => true | ||
after_create :create_subdomain | ||
before_create :create_subdomain | ||
|
||
private | ||
|
||
def create_subdomain | ||
subdomain = Subdomain.find_by_name(self.subdomain_name) | ||
if !subdomain | ||
Subdomain.create! :name => self.subdomain_name, :user_id => self.id | ||
end | ||
self.subdomain = Subdomain.find_by_name(self.subdomain_name) | ||
self.subdomain ||= Subdomain.create!(:name => self.subdomain_name, :user_id => self.id) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,4 +26,4 @@ def self.up | |
def self.down | ||
drop_table :users | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class MigrateSubdomainToInteger < ActiveRecord::Migration | ||
def self.up | ||
remove_column :users, :subdomain_name | ||
add_column :users, :subdomain_id, :integer | ||
add_index :users, :subdomain_id | ||
add_index :subdomains, :name | ||
end | ||
|
||
def self.down | ||
add_column :users, :subdomain_name, :limit => 40 | ||
remove_column :users, :subdomain_id | ||
remove_index :users, :subdomain_id | ||
remove_index :subdomains, :name | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters