Rails Groupify gem

2019-06-01 09:57发布

问题:

I set it up as per the documentation (I think): https://github.com/dwbutler/groupify

But then in the console:

user=User.new

group=Group.new

group.add user

user.in_group?(group)

=> false

Returns false, instead of true.

Problem.

I don't get it. I've a few different things and no joy. I'm stuck.

My latest attempt is here: https://github.com/Yorkshireman/sebcoles/tree/setup3 (setup3 branch)

I have a previous attempt on the setup2 branch.

There is little difference between the two branches (the migrations and subsequent scheme.rb were SLIGHTLY different).

Help!

回答1:

I am guessing you have to save the attributes of the group, ex: type, membership_type etc.. Also, I m guessing that the user has to be saved in the database. User.new does not save anything. Same as Group.new. User.create or User.save will help



回答2:

This is a while ago now, and I stopped using the groupify gem for my project, but I think I did get it working before I stopped using it, and I think it was actually because I was using 'group' and 'user' as the variable names (as in the above routine in the original post).

Try doing:

user1 = User.new
group1 = Group.new
group1.add user1
user1.in_group?(group1)

Should (hopefully) return true!



回答3:

Make sure user.rb model includes

#For Groupify Gem 
groupify :group_member 
groupify :named_group_member