简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM