Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Andrew Stelmach
12,583 PointsGroupify NameError
After setting up Groupify as per the documentation, I launch my console and do:
user = User.new
group = Group.new
group.add user
This returns the following error:
NameError: uninitialized constant User::GroupMembership
I can't for the life of me work out this problem. You can check out Groupify's documentation on Github, and here are my models:
user.rb:
class User < ActiveRecord::Base
authenticates_with_sorcery!
validates :name, presence: true
validates :password, length: { minimum: 4 }
validates :password, confirmation: true
validates :password_confirmation, presence: true
validates :email, uniqueness: true
has_many :testimonials
has_many :materials
groupify :group_member
groupify :named_group_member
end
class Assignment < ActiveRecord::Base
groupify :group_member
end
group.rb:
class Group < ActiveRecord::Base
groupify :group, members: [:users, :assignments], default_members: :users
end
groupmembership.rb:
class GroupMembership < ActiveRecord::Base
groupify :group_membership
end
schema.rb:
ActiveRecord::Schema.define(version: 20150301133633) do
create_table "group_memberships", force: :cascade do |t|
t.string "member_type"
t.integer "member_id"
t.integer "group_id"
t.string "group_name"
t.string "membership_type"
end
add_index "group_memberships", ["group_id"], name: "index_group_memberships_on_group_id"
add_index "group_memberships", ["group_name"], name: "index_group_memberships_on_group_name"
add_index "group_memberships", ["member_id", "member_type"], name: "index_group_memberships_on_member_id_and_member_type"
create_table "groups", force: :cascade do |t|
t.string "type"
end
create_table "users", force: :cascade do |t|
t.string "email", null: false
t.string "crypted_password"
t.string "salt"
t.datetime "created_at"
t.datetime "updated_at"
t.string "name"
end
add_index "users", ["email"], name: "index_users_on_email", unique: true
end
1 Answer

Maciej Czuchnowski
36,441 PointsWait, is your GroupMembership model file name groupmembership.rb or is it a typo in the above post? The camel case suggests it should be group_membership.rb.
Andrew Stelmach
12,583 PointsAndrew Stelmach
12,583 PointsIt's groupmembership.rb. That might be it; I'll try it later.
Andrew Stelmach
12,583 PointsAndrew Stelmach
12,583 PointsWorked! Thanks man. I feel a bit stupid, but it just goes to show why it's important to get a solid foundation of knowledge. I'm spending more time reading my book these days, rather than just hacking through code (but I do still hack a bit :-) )
Maciej Czuchnowski
36,441 PointsMaciej Czuchnowski
36,441 PointsGlad it worked :). I don't think this is explicitly explained anywhere. It's just a pattern I picked up at some point.