Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding users to groups #56

Open
zaheenzkhan opened this issue Apr 10, 2017 · 3 comments
Open

Adding users to groups #56

zaheenzkhan opened this issue Apr 10, 2017 · 3 comments
Labels

Comments

@zaheenzkhan
Copy link

zaheenzkhan commented Apr 10, 2017

@dwbutler I am a newbie on rails 5 and cannot seem to add users to my groups. my group_membership table is empty.
Can someone help me with an example? even the syntax would help.

@dwbutler
Copy link
Owner

The readme has plenty of examples. If you can post a code sample I can probably tell you what's wrong with it.

@zaheenzkhan
Copy link
Author

zaheenzkhan commented Apr 17, 2017

class User < ApplicationRecord

     devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable


    groupify :group_member
    groupify :named_group_member

    validates :email, :presence => true, :uniqueness => true
    has_many :members
    has_many :groups, through: :member
end

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

    has_many :members
    has_many :groups, through: :member
end

class Member < ApplicationRecord
    belongs_to :group
    belongs_to :user
end

class Membership < ApplicationRecord
    groupify :group_membership
end

These are all the models i have created. I can create new users and groups but i cant add users to groups, neither through groupify or the has_many & through association (you can see i tried both). Also i cannot populate the member or the Membership(groupify) tables. need help

What are the commands that i should be using?

@dwbutler
Copy link
Owner

If you're defining your own associations that override groupify's, that could be problematic.

Some basic troubleshooting steps:

  • Have you run the migrations? rake db:migrate
  • Does your rails log (in logs/development.log) have any error messages?
  • What code are you actually running to try to add users to groups?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants