shayonj
shayonj

Reputation: 910

Create groups with rails and invite them

I have basic rails app and using devise for authetication. that being said, I have a User model. Now, I would like to have a groups feature in my app where a User can create and invite others to join groups.

SO how do i create groups and also since i have devise setup already how can use devise invitable plugin to invite and add as members of the group ?

thanks

Upvotes: 4

Views: 3201

Answers (1)

Don Leatham
Don Leatham

Reputation: 2704

From what I've seen, most "group" functionality in Rails is built off the idea that there is a many-to-many relationship between users and groups. Groups hold as members many users, and users have membership in many groups. So it is pretty straight forward to implement groups using the has_many :through relationship provided by ActiveRecord. Here is a most basic implementation:

class Group
  has_many :users, :through => :memberships
end

class User
  has_many :groups, :through => :memberships
end

class Membership
  belongs_to :group
  belongs_to :user
end

Take a minute to look at the Rails Guide that addresses ActiveRecord associations and you will get the picture.

I'm pretty sure the Devise Invitable plug-in is used to invite someone to create a registration at your site, not to invite them to join a group within your site. I'm not aware of any gems that manage a group membership invitation system.

If groups are a core aspect of what you are doing with your site you might want to look at some of the CMS options built on RoRs. I think some of them have full group management capabilities. Here is a resource: https://www.ruby-toolbox.com/categories/content_management_systems

Hope this helps.

Upvotes: 5

Related Questions