Skip to content

Instantly share code, notes, and snippets.

@fourfour
Created August 21, 2014 04:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fourfour/0cf77b1ad8344f40106d to your computer and use it in GitHub Desktop.
Save fourfour/0cf77b1ad8344f40106d to your computer and use it in GitHub Desktop.
class User < ActiveRecord::Base
acts_as_group_member
acts_as_named_group_member
end
class Manager < User
end
class GroupMembership < ActiveRecord::Base
acts_as_group_membership
end
class Group < ActiveRecord::Base
acts_as_group :members => [:users], :default_members => :users
end
# Migrations
class CreateGroups < ActiveRecord::Migration
def change
create_table :groups do |t|
t.string :name
t.string :type
t.timestamps
end
end
end
class CreateGroupMemberships < ActiveRecord::Migration
def change
create_table :group_memberships do |t|
t.string :member_type
t.integer :member_id
t.integer :group_id
t.string :group_name
t.string :membership_type
end
end
end
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name
t.string :type
t.timestamps
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment