Skip to content

Commit b67a5af

Browse files
committed
Add report mailer
1 parent 376dc44 commit b67a5af

14 files changed

+128
-8
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@
1515
/log/*
1616
!/log/.keep
1717
/tmp
18+
19+
/config/application.yml

Gemfile

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ gem 'compass-rails', '~> 2.0.4'
1616
gem 'compass-susy-plugin'
1717
gem 'susy'
1818

19+
gem 'mailgun_rails'
20+
gem 'settingslogic'
21+
1922
group :development, :test do
2023
gem 'byebug'
2124
gem 'web-console', '~> 2.0'

Gemfile.lock

+27-8
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ GEM
4747
coffee-rails (4.1.0)
4848
coffee-script (>= 2.2.0)
4949
railties (>= 4.0.0, < 5.0)
50-
coffee-script (2.3.0)
50+
coffee-script (2.4.1)
5151
coffee-script-source
5252
execjs
53-
coffee-script-source (1.9.1)
53+
coffee-script-source (1.9.1.1)
5454
columnize (0.9.0)
5555
compass (1.0.3)
5656
chunky_png (~> 1.2)
@@ -78,14 +78,18 @@ GEM
7878
responders
7979
thread_safe (~> 0.1)
8080
warden (~> 1.2.3)
81+
domain_name (0.5.24)
82+
unf (>= 0.0.5, < 1.0.0)
8183
erubis (2.7.0)
82-
execjs (2.4.0)
84+
execjs (2.5.2)
8385
ffi (1.9.8)
84-
globalid (0.3.3)
86+
globalid (0.3.5)
8587
activesupport (>= 4.1.0)
8688
hike (1.2.3)
89+
http-cookie (1.0.2)
90+
domain_name (~> 0.5)
8791
i18n (0.7.0)
88-
jbuilder (2.2.12)
92+
jbuilder (2.2.13)
8993
activesupport (>= 3.0.0, < 5)
9094
multi_json (~> 1.2)
9195
jquery-rails (4.0.3)
@@ -97,10 +101,15 @@ GEM
97101
nokogiri (>= 1.5.9)
98102
mail (2.6.3)
99103
mime-types (>= 1.16, < 3)
100-
mime-types (2.4.3)
104+
mailgun_rails (0.7.0)
105+
actionmailer (>= 3.2.13)
106+
json (>= 1.7.7)
107+
rest-client (>= 1.6.7)
108+
mime-types (2.5)
101109
mini_portile (0.6.2)
102-
minitest (5.5.1)
110+
minitest (5.6.0)
103111
multi_json (1.11.0)
112+
netrc (0.10.3)
104113
nokogiri (1.6.6.2)
105114
mini_portile (~> 0.6.0)
106115
orm_adapter (0.5.0)
@@ -139,6 +148,10 @@ GEM
139148
json (~> 1.4)
140149
responders (2.1.0)
141150
railties (>= 4.2.0, < 5)
151+
rest-client (1.8.0)
152+
http-cookie (>= 1.0.2, < 2.0)
153+
mime-types (>= 1.16, < 3.0)
154+
netrc (~> 0.7)
142155
sass (3.4.13)
143156
sass-rails (5.0.1)
144157
railties (>= 4.0.0, < 5.0)
@@ -149,7 +162,8 @@ GEM
149162
sdoc (0.4.1)
150163
json (~> 1.7, >= 1.7.7)
151164
rdoc (~> 4.0)
152-
spring (1.3.3)
165+
settingslogic (2.0.9)
166+
spring (1.3.4)
153167
sprockets (2.12.3)
154168
hike (~> 1.2)
155169
multi_json (~> 1.0)
@@ -172,6 +186,9 @@ GEM
172186
uglifier (2.7.1)
173187
execjs (>= 0.3.0)
174188
json (>= 1.8.0)
189+
unf (0.1.4)
190+
unf_ext
191+
unf_ext (0.0.7.1)
175192
warden (1.2.3)
176193
rack (>= 1.0)
177194
web-console (2.1.2)
@@ -191,9 +208,11 @@ DEPENDENCIES
191208
devise
192209
jbuilder (~> 2.0)
193210
jquery-rails
211+
mailgun_rails
194212
rails (= 4.2.1)
195213
sass-rails (~> 5.0)
196214
sdoc (~> 0.4.0)
215+
settingslogic
197216
spring
198217
sqlite3
199218
susy

app/controllers/candidate_profile_controller.rb

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ def create
33
p params
44
@profile = CandidateProfile.new(candidate_params)
55
if @profile.save
6+
CandidateMailer.report_new_candidate_email(@profile).deliver_now
67
render :post_submit
78
else
89
flash[:notice] = "Nu toate campurile obligatorii sunt completate"

app/mailers/candidate_mailer.rb

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class CandidateMailer < ActionMailer::Base
2+
default from: "[email protected]"
3+
layout 'mailer'
4+
5+
def report_new_candidate_email(profile)
6+
@profile = profile
7+
mail(
8+
:to => Settings.admin_email,
9+
:subject => "New Candidate has been registered!"
10+
)
11+
end
12+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
<h4>Candidate: <%= @profile.name %></h4>
3+
<% %w(email phone city activity studies age).each do |item| %>
4+
<p><b><%= "#{item.titleize}: " %></b><%= @profile.public_send(item) %></p>
5+
<% end %>
6+
7+
<% %w(motivation voluntariat
8+
project_idea
9+
teamwork
10+
last_skill
11+
agreement
12+
disagreement_comment).each do |item| %>
13+
<h4><%= "#{item.titleize}:" %></h4>
14+
<p>
15+
<%= @profile.public_send(item) %>
16+
</p>
17+
<% end %>
18+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
3+
Candidate: <%= @profile.name %>
4+
--------------------
5+
<% %w(email phone city activity studies age).each do |item| %>
6+
<%= "#{item.titleize}: #{@profile.public_send(item)}" %>
7+
8+
<% end %>
9+
--------------------
10+
<% %w(motivation voluntariat
11+
project_idea
12+
teamwork
13+
last_skill
14+
agreement
15+
disagreement_comment).each do |item| %>
16+
<%= "#{item.titleize}:" %>
17+
<%= @profile.public_send(item) %>
18+
--------------------
19+
<% end %>
20+
21+

app/views/layouts/mailer.html.erb

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<html>
2+
<body>
3+
<%= yield %>
4+
</body>
5+
</html>

app/views/layouts/mailer.text.erb

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<%= yield %>

config/application.example.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
defaults: &defaults
2+
admin_email: [email protected]
3+
mailgun:
4+
api_key: "mailgun-api-key"
5+
domain: "mailgun-domain"
6+
7+
development:
8+
<<: *defaults
9+
10+
test:
11+
<<: *defaults
12+
13+
production:
14+
<<: *defaults
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
class Settings < Settingslogic
3+
source "#{Rails.root}/config/application.yml"
4+
namespace Rails.env
5+
load!
6+
end

config/initializers/mailgun.rb

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
Rails.application.config.action_mailer.perform_deliveries = true
3+
Rails.application.config.action_mailer.delivery_method = :mailgun
4+
Rails.application.config.action_mailer.mailgun_settings = {
5+
:api_key => Settings.mailgun.api_key,
6+
:domain => Settings.mailgun.domain
7+
}

test/mailers/candidate_mailer_test.rb

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
require 'test_helper'
2+
3+
class CandidateMailerTest < ActionMailer::TestCase
4+
# test "the truth" do
5+
# assert true
6+
# end
7+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Preview all emails at http://localhost:3000/rails/mailers/candidate_mailer
2+
class CandidateMailerPreview < ActionMailer::Preview
3+
4+
end

0 commit comments

Comments
 (0)