Skip to content

Commit

Permalink
add notice by mail to cancel event
Browse files Browse the repository at this point in the history
  • Loading branch information
raul-fuentes committed Dec 5, 2017
1 parent 37e95ea commit 1470dbd
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/mailers/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class ApplicationMailer < ActionMailer::Base
default from: "from@example.com"
layout 'mailer'
end
13 changes: 13 additions & 0 deletions app/mailers/event_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class EventMailer < ApplicationMailer

def cancel(event)
user = event.user
@reasons = event.reasons
@canceled_at = l event.canceled_at, format: :short
@event_title = event.title
@name = user.full_name
subject = t('mailers.cancel_event.subject', title: @event_title)
mail(to: user.email, subject: subject)
end

end
1 change: 1 addition & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def cancel_event
if cancel == 'true' and canceled_at.nil?
self.canceled_at = Time.zone.today
self.status = 'canceled'
EventMailer.cancel(self).deliver_now
end
end

Expand Down
25 changes: 25 additions & 0 deletions app/views/event_mailer/cancel.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<td style="padding-bottom: 20px; padding-left: 10px;">
<h1 style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;">
<%= t('mailers.cancel_event.welcome', name: @name) %>
</h1>

<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
<%= t('mailers.cancel_event.text1', title: @event_title) %>
</p>

<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
<%= t('mailers.cancel_event.text2') %>
</p>

<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
<%= raw @reasons %>
</p>

<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
<%= t('mailers.cancel_event.canceled_at', canceled_at: @canceled_at) %>
</p>

<p style="font-family: 'Open Sans','Helvetica Neue',arial,sans-serif;font-size: 14px;font-weight: normal;line-height: 24px;">
<%= t('mailers.cancel_event.thanks') %>
</p>
</td>
5 changes: 5 additions & 0 deletions app/views/layouts/mailer.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
<%= yield %>
</body>
</html>
1 change: 1 addition & 0 deletions app/views/layouts/mailer.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= yield %>
9 changes: 9 additions & 0 deletions config/locales/mailers.en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
en:
mailers:
cancel_event:
subject: "Cancelled event: %{title}"
welcome: "Hello %{name}"
text1: "The event: %{title}"
text2: "Has been cancelled for the following reason:"
canceled_at: "On %{canceled_at}"
thanks: "Regards"
9 changes: 9 additions & 0 deletions config/locales/mailers.es.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
es:
mailers:
cancel_event:
subject: "Cancelado evento: %{title}"
welcome: "Hola %{name}"
text1: "El evento: %{title}"
text2: "Ha sido cancelado por la siguiente razón:"
canceled_at: "A día %{canceled_at}"
thanks: "Un saludo"
5 changes: 5 additions & 0 deletions spec/mailers/event_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require "rails_helper"

RSpec.describe EventMailer, type: :mailer do
pending "add some examples to (or delete) #{__FILE__}"
end
9 changes: 9 additions & 0 deletions spec/mailers/previews/event_mailer_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Preview all emails at http://localhost:3000/rails/mailers/event_mailer
class EventMailerPreview < ActionMailer::Preview

def cancel
event = Event.second
EventMailer.cancel(event)
end

end

0 comments on commit 1470dbd

Please sign in to comment.