I would like Users who are members in a Group to be able to share and invite other users through a unique url. I’m having trouble figuring out how to do this. My initial assumption is to generate a link using Digest::MD5.hexdigest and adding a method to the Group model. I’m not sure if this is the right approach.
The functionality is as followed:
-
User creates a group (automatically set as the admin)
-
Admin user can invite other users through the unique share link. He emails, messages, etc. this unique url to the people he would link in the group
-
The invited user clicks the link and is directed to the groups show page where he is prompted to login or create an account
-
Newly added user can now also invite other users with a unique share link.
class Group < ActiveRecord::Base attr_accessible :name, :share_link has_many :memberships has_many :users, :through => :memberships validates: name, presence: :true def generate_link(user) Digest::MD5.hexdigest("#{self.created_at}#{user.id}") end end class Membership < ActiveRecord::Base belongs_to :user belongs_to :group attr_accessible :group_id, :user_id, :admin end class Post < ActiveRecord::Base belongs_to :user attr_accessible :title, :url, :user_id validates :title, presence: :true end class User < ActiveRecord::Base attr_accessible :name, :provider, :uid has_many :memberships has_many :groups, :through => :memberships has_many :posts end
Routes
WeeklyTrim::Application.routes.draw do
resources :groups, :except => [:index] do
resources :posts
end
get "sessions/create"
get "pages/home"
get "pages/welcome"
get "pages/no_access"
post "groups/email"
post "/join_groups/create"
delete "/join_groups/destroy"
match "/welcome" => "pages#welcome"
match "/pages/no_access" => "pages#no_access"
match "/auth/:provider" => redirect("http://#{DOMAIN_NAME}/auth/#{:provider}"), :as => :signin
match '/auth/:provider/callback' => 'sessions#create'
match '/signout' => 'sessions#destroy', :as => :signout
root :to => 'pages#index'
end