diff --git a/app/controllers/recipients_controller.rb b/app/controllers/recipients_controller.rb index ad3bb4a4..36ccb4f4 100644 --- a/app/controllers/recipients_controller.rb +++ b/app/controllers/recipients_controller.rb @@ -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 diff --git a/app/models/recipient.rb b/app/models/recipient.rb index e5106070..2ab7b684 100644 --- a/app/models/recipient.rb +++ b/app/models/recipient.rb @@ -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 diff --git a/app/views/schools/show.html.haml b/app/views/schools/show.html.haml index ca5b69b9..f890c782 100644 --- a/app/views/schools/show.html.haml +++ b/app/views/schools/show.html.haml @@ -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?'})