mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-07 13:38:18 -08:00
showing all recipients
This commit is contained in:
parent
1387612623
commit
d9005797a4
3 changed files with 27 additions and 15 deletions
|
|
@ -40,8 +40,8 @@ class RecipientsController < ApplicationController
|
|||
|
||||
def import
|
||||
render and return if request.get?
|
||||
|
||||
Recipient.import(params[:file])
|
||||
|
||||
Recipient.import(@school, params[:file])
|
||||
redirect_to @school, notice: "Recipients imported."
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -8,14 +8,15 @@ class Recipient < ApplicationRecord
|
|||
|
||||
def self.import(school, file)
|
||||
CSV.foreach(file.path, headers: true) do |row|
|
||||
recipient_hash = row.to_hash
|
||||
recipient = school.recipients.where(phone: recipient_hash["phone"])
|
||||
|
||||
if recipient.count == 1
|
||||
recipient.first.update_attributes(recipient_hash)
|
||||
else
|
||||
school.recipients.create!(recipient_hash)
|
||||
end
|
||||
school.recipients.create!(row.to_hash)
|
||||
# recipient_hash = row.to_hash
|
||||
# recipient = school.recipients.where(phone: recipient_hash["phone"])
|
||||
#
|
||||
# if recipient.count == 1
|
||||
# recipient.first.update_attributes(recipient_hash)
|
||||
# else
|
||||
# school.recipients.create!(recipient_hash)
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -13,8 +13,19 @@
|
|||
|
|
||||
= link_to 'Back', root_path
|
||||
|
||||
- @school.recipients.each do |recipient|
|
||||
.recipient
|
||||
%p
|
||||
%strong= recipient.name
|
||||
= recipient.phone
|
||||
%br
|
||||
%br
|
||||
%br
|
||||
%h4 School Recipients
|
||||
%table{style: 'width: 100%;'}
|
||||
%tbody
|
||||
%thead
|
||||
%th Name
|
||||
%th Phone
|
||||
%th{colspan: 2} Actions
|
||||
- @school.recipients.each do |recipient|
|
||||
%tr.recipient
|
||||
%td= recipient.name
|
||||
%td= recipient.phone
|
||||
%td= link_to('Edit', edit_school_recipient_path(@school, recipient))
|
||||
%td= link_to('Delete', school_recipient_path(@school, recipient), method: :delete, data: {confirm: 'Are you sure you want to delete this recipient?'})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue