meritonch
meritonch

Reputation: 43

Sending emails to multiple recipients in rails app

So I'm creating a Support Ticketing System.

I need some help on creating teams from my User table, so users of the app can assign tickets to team, and the whole team can get an email once a ticket is created and they belong to that team.

I have Department, Ticket and User models.

Any ideas?

Upvotes: 0

Views: 75

Answers (1)

Prakash Murthy
Prakash Murthy

Reputation: 13077

Assuming

  1. one user can belong to only one team, and
  2. one ticket is assigned to one team.

the following class structure could work:

class Department < ActiveRecord::Base
end

class Ticket < ActiveRecord::Base
  belongs_to :team
end

class User < ActiveRecord::Base
  belongs_to :team
end

class Team < ActiveRecord::Base
  has_many :users
  has_many :tickets
end

This allows for the following:

t = Ticket.find(...) # Find a specific ticket with id
t.team # The team assigned to which the ticket is assigned to
t.team.users  # Users belonging to that team
t.team.users.map(&:email)  # Array of emails for the users belonging to that team, assuming there is an email field in the `User` model.

Upvotes: 2

Related Questions