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! While you're at it, check out some resources Treehouse students have shared here.

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


Groupify 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:


class User < ActiveRecord::Base

    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

class Assignment < ActiveRecord::Base
  groupify :group_member


class Group < ActiveRecord::Base  
  groupify :group, members: [:users, :assignments], default_members: :users


class GroupMembership < ActiveRecord::Base  
  groupify :group_membership


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"

  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"

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"

  add_index "users", ["email"], name: "index_users_on_email", unique: true


1 Answer

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

Wait, 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.

It's groupmembership.rb. That might be it; I'll try it later.

Worked! 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
Maciej Czuchnowski
36,441 Points

Glad it worked :). I don't think this is explicitly explained anywhere. It's just a pattern I picked up at some point.