I’m having a lot of trouble with has_many, :through and could really
use some assistance.
I’ve got a User and Group class. Users can subscribe to groups, and
groups should know who’s subscribed.
I’ve got a join table (group_subscriptions) with group_id, user_id,
and it’s own id element.
Users has “has_many :groups, :through => :group_subscription” and
Groups has “has_many :users, :through => :group_subscription”. I
also have a group_subscription.rb model that has “belongs_to :user
newline belongs_to :group”
I just wanted to test out working with this kind of functionality, so
I’ve got this simple code:
@user = User.find(1)
@group = Group.find(1)
@user.groups << @group
but I get the error
“ActiveRecord::HasManyThroughAssociationNotFoundError”. I’m running
Webrick on OS X, have restarted it, and have looked everywhere to no
avail in this problem.