showing all recipients

pull/1/head
Jared Cosulich 9 years ago
parent 1387612623
commit d9005797a4

@ -40,8 +40,8 @@ class RecipientsController < ApplicationController
def import def import
render and return if request.get? render and return if request.get?
Recipient.import(params[:file]) Recipient.import(@school, params[:file])
redirect_to @school, notice: "Recipients imported." redirect_to @school, notice: "Recipients imported."
end end

@ -8,14 +8,15 @@ class Recipient < ApplicationRecord
def self.import(school, file) def self.import(school, file)
CSV.foreach(file.path, headers: true) do |row| CSV.foreach(file.path, headers: true) do |row|
recipient_hash = row.to_hash school.recipients.create!(row.to_hash)
recipient = school.recipients.where(phone: recipient_hash["phone"]) # recipient_hash = row.to_hash
# recipient = school.recipients.where(phone: recipient_hash["phone"])
if recipient.count == 1 #
recipient.first.update_attributes(recipient_hash) # if recipient.count == 1
else # recipient.first.update_attributes(recipient_hash)
school.recipients.create!(recipient_hash) # else
end # school.recipients.create!(recipient_hash)
# end
end end
end end

@ -13,8 +13,19 @@
| |
= link_to 'Back', root_path = link_to 'Back', root_path
- @school.recipients.each do |recipient| %br
.recipient %br
%p %br
%strong= recipient.name %h4 School Recipients
= recipient.phone %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…
Cancel
Save