Skip to content

Commit

Permalink
add a Group subclass (STI) called Homepage - a personal staging group…
Browse files Browse the repository at this point in the history
… per user account, modify User model to autmoatically create the homepage
  • Loading branch information
Boon Low committed May 14, 2010
1 parent a5ac476 commit 356728a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/models/homepage.rb
@@ -0,0 +1,3 @@
class Homepage < Group

end
14 changes: 14 additions & 0 deletions app/models/user.rb
@@ -1,8 +1,12 @@
class User < ActiveRecord::Base

before_create :create_profile

# Each user owns a homepage (subclass of group)
after_create :create_homepage

has_one :profile, :dependent => :destroy
has_one :homepage, :dependent => :destroy

has_many :memberships, :dependent => :destroy
has_many :plain_memberships, :class_name => 'Membership',
Expand Down Expand Up @@ -35,5 +39,15 @@ def network
def create_profile
self.profile ||= Profile.new
end

def create_homepage
@group = Homepage.new(:name=> self.login + "'s homepage", :description => "A personal space (homepage) of " + self.login + " where objects can be shared to or from, in various contexts such as posts, links.")
@group.author = self
@group.private = true
@group.save
@group.activate!
@group.join(self, true)
@group.activate_membership(self)
end

end
9 changes: 9 additions & 0 deletions db/migrate/008_add_type_to_groups.rb
@@ -0,0 +1,9 @@
class AddTypeToGroups < ActiveRecord::Migration
def self.up
add_column :groups, :type, :string
end

def self.down
remove_column :groups, :type
end
end

0 comments on commit 356728a

Please sign in to comment.