Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

modify the User model

  • Loading branch information...
commit 90e3b7da949220b824994d425d6d8ed596b82c1c 1 parent 37b8893
@fortuity authored
Showing with 17 additions and 0 deletions.
  1. +15 −0 README
  2. +2 −0  app/models/user.rb
View
15 README
@@ -363,6 +363,21 @@ class Subdomain < ActiveRecord::Base
end
end
+Modify the User Model to Have Subdomains
+
+Subdomains belong to users, so we have to set up the User side of the relationship. We'll also modify the User model so the URL for accessing a user uses a name instead of a number:
+
+class User < ActiveRecord::Base
+ has_many :subdomains, :dependent => :destroy
+ has_friendly_id :name
+ # Include default devise modules.
+ # Others available are :lockable, :timeoutable and :activatable.
+ devise :authenticatable, :confirmable, :recoverable, :rememberable, :trackable, :validatable
+
+ # Setup accessible (or protected) attributes for your model
+ attr_accessible :email, :password, :password_confirmation
+end
+
Create a Site Model
We'll create a Site model as a subclass of the Subdomain model so that each user can view a site at their subdomain. The Site is a simple stub in this application. It can be customized for additional functionality (for example, implementation as a blog).
View
2  app/models/user.rb
@@ -1,4 +1,6 @@
class User < ActiveRecord::Base
+ has_many :subdomains, :dependent => :destroy
+ has_friendly_id :name
# Include default devise modules.
# Others available are :lockable, :timeoutable and :activatable.
devise :authenticatable, :confirmable, :recoverable, :rememberable, :trackable, :validatable
Please sign in to comment.
Something went wrong with that request. Please try again.