Skip to content

Commit

Permalink
Testing mailer
Browse files Browse the repository at this point in the history
  • Loading branch information
tallenaz committed Jun 7, 2016
1 parent 218f740 commit f22f0f1
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/controllers/change_item_types_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@ def new
@change_item_type = ChangeItemType.new
end

# rubocop:disable Metrics/MethodLength
def create
change_item_type = ChangeItemType.new(params[:change_item_type])
if change_item_type.valid?
array_of_item_ids = change_item_type.parse_uploaded_file
@uni_updates_batch = UniUpdatesBatch.create_item_type_batch(params)
UniUpdates.create_item_type_updates(array_of_item_ids, @uni_updates_batch)
WebformsMailer.batch_upload_email(@uni_updates_batch).deliver_now
flash[:notice] = 'Batch updated!'
redirect_to @uni_updates_batch
else
render action: 'new'
end
end
# rubocop:enable Metrics/MethodLength
end
10 changes: 10 additions & 0 deletions app/mailers/webforms_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# app/mailers/webforms_mailer.rb
class WebformsMailer < ActionMailer::Base
default from: 'azanella@example.com'

def batch_upload_email(uni_updates_batch)
@uni_updates_batch = uni_updates_batch
destination = 'azanella@stanford.edu'
mail(to: destination, subject: 'batch record update')
end
end
17 changes: 17 additions & 0 deletions app/views/webforms_mailer/batch_upload_email.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<h1><%= @uni_updates_batch.uni_updates.count %> barcodes entered into the batch update table with values:</h1>
<p>Batch id: <%= @uni_updates_batch.batch_id %></p>
<p>Requested action: <%= @uni_updates_batch.action %></p>
<p>Batch comments: <%= @uni_updates_batch.comments %></p>
<p>Current library: <%= @uni_updates_batch.orig_lib %></p>
<p>New library: <%= @uni_updates_batch.new_lib %></p>
<p>New home location: <%= @uni_updates_batch.new_homeloc %></p>
<p>New current location: <%= @uni_updates_batch.new_curloc %></p>
<p>New item type: <%= @uni_updates_batch.new_itype %></p>
</body>
</html>
11 changes: 11 additions & 0 deletions app/views/webforms_mailer/batch_upload_email.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<%= @uni_updates_batch.uni_updates.count %> barcodes entered into the batch update table with values:
======================================================================================================

Batch id: <%= @uni_updates_batch.batch_id %>
Requested action: <%= @uni_updates_batch.action %>
Batch comments: <%= @uni_updates_batch.comments %>
Current library: <%= @uni_updates_batch.orig_lib %>
New library: <%= @uni_updates_batch.new_lib %>
New home location: <%= @uni_updates_batch.new_homeloc %>
New current location: <%= @uni_updates_batch.new_curloc %>
New item type: <%= @uni_updates_batch.new_itype %>

0 comments on commit f22f0f1

Please sign in to comment.