Rails Groupify gem

*爱你&永不变心* 提交于 2019-12-08 04:49:59

问题


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


来源:https://stackoverflow.com/questions/29112512/rails-groupify-gem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!