我有一个员工阵列。
employees = TeamEmployee.where(:team_id => business.team_id).pluck(:employee_id)
我想使用我已在我的应用中安装的通知gem为每位员工创建通知
我的循环如下。
nex = business.next_member
employees.each do |emp|
note = Notification.create(notify_type: 'create_ticket', actor:
ticket.assignee, user: emp.id, target: ticket, acceptance:true,
message: "#{ticket.title} for Room #{ticket.room.location} has been
created. Do you accept?" ) if nex.blank?
accept_event = AcceptanceEvent.create(business_id:
business.id,notification_id: note.id,accepted:false,timer_hours:
business.wait_hours,timer_minutes: business.wait_minutes)
end
当我创建数组索引的单个通知时,它工作正常。
有人可以建议我如何构建数组循环来向数组的每个索引发送通知吗?
答案 0 :(得分:0)
我想出了答案,我只需要使用employee数组索引从用户表中调用该用户,然后才能将其分配给通知用户属性
employees.each do |emp|
user = User.where('id = ?', emp)[0]
note = Notification.create(notify_type: 'create_ticket', actor:
ticket.assignee, user: user, target: ticket, acceptance:true,
message: "#{ticket.title} for Room #{ticket.room.location} has been
created. Do you accept?" )
accept_event = AcceptanceEvent.create(business_id:
business.id,notification_id: note.id,accepted:false,timer_hours:
business.wait_hours,timer_minutes: business.wait_minutes)
end