diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2023-10-12 21:51:02 -0400 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2023-10-12 21:51:02 -0400 |
commit | 9ad3bca2ea475b709c8311ab25194e4578c1a0d9 (patch) | |
tree | b60fa4048784bb36853d461fc6df14579a241534 | |
parent | 2022e18daab968ad49af9b3e59969ef1ed110436 (diff) | |
download | thoughts-9ad3bca2ea475b709c8311ab25194e4578c1a0d9.tar.gz thoughts-9ad3bca2ea475b709c8311ab25194e4578c1a0d9.tar.bz2 thoughts-9ad3bca2ea475b709c8311ab25194e4578c1a0d9.zip |
Webmaster gets an email when a comment is posted
-rw-r--r-- | app/controllers/comments_controller.rb | 4 | ||||
-rw-r--r-- | app/mailers/application_mailer.rb | 2 | ||||
-rw-r--r-- | app/mailers/comment_mailer.rb | 7 | ||||
-rw-r--r-- | app/views/comment_mailer/new_comment_email.html.haml | 22 | ||||
-rw-r--r-- | app/views/comment_mailer/new_comment_email.text.erb | 20 | ||||
-rw-r--r-- | config/deploy.rb | 2 | ||||
-rw-r--r-- | config/environments/development.rb | 1 | ||||
-rw-r--r-- | config/environments/production.rb | 4 | ||||
-rw-r--r-- | config/mail.yml | 8 | ||||
-rw-r--r-- | test/mailers/comment_mailer_test.rb | 7 | ||||
-rw-r--r-- | test/mailers/previews/comment_mailer_preview.rb | 4 |
11 files changed, 78 insertions, 3 deletions
diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 60c8f6a..c66365b 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb | |||
@@ -43,6 +43,10 @@ class CommentsController < ApplicationController | |||
43 | 43 | ||
44 | if @comment.save | 44 | if @comment.save |
45 | flash.notice = flash_message | 45 | flash.notice = flash_message |
46 | |||
47 | if @comment.status == :published | ||
48 | CommentMailer.with(comment: @comment).new_comment_email.deliver_later | ||
49 | end | ||
46 | else | 50 | else |
47 | flash.alert = "Error posting comment." | 51 | flash.alert = "Error posting comment." |
48 | end | 52 | end |
diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 286b223..4862159 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb | |||
@@ -1,4 +1,4 @@ | |||
1 | class ApplicationMailer < ActionMailer::Base | 1 | class ApplicationMailer < ActionMailer::Base |
2 | default from: 'from@example.com' | 2 | default from: 'no-reply@fourisland.com' |
3 | layout 'mailer' | 3 | layout 'mailer' |
4 | end | 4 | end |
diff --git a/app/mailers/comment_mailer.rb b/app/mailers/comment_mailer.rb new file mode 100644 index 0000000..363875a --- /dev/null +++ b/app/mailers/comment_mailer.rb | |||
@@ -0,0 +1,7 @@ | |||
1 | class CommentMailer < ApplicationMailer | ||
2 | def new_comment_email | ||
3 | @comment = params[:comment] | ||
4 | @admin = User.first # this is weird | ||
5 | mail(to: @admin.email, subject: "[Four Island] Comment on #{@comment.blog.title}") | ||
6 | end | ||
7 | end | ||
diff --git a/app/views/comment_mailer/new_comment_email.html.haml b/app/views/comment_mailer/new_comment_email.html.haml new file mode 100644 index 0000000..bd9e91c --- /dev/null +++ b/app/views/comment_mailer/new_comment_email.html.haml | |||
@@ -0,0 +1,22 @@ | |||
1 | %h1 Four Island | ||
2 | %p | ||
3 | A comment has been posted on | ||
4 | = link_to @comment.blog.title, @comment.blog | ||
5 | by the following user: | ||
6 | %ul | ||
7 | %li | ||
8 | Name: | ||
9 | = @comment.username | ||
10 | %li | ||
11 | Email: | ||
12 | = @comment.email | ||
13 | - unless @comment.website.empty? | ||
14 | %li | ||
15 | Website: | ||
16 | = @comment.website | ||
17 | %p Here is the comment: | ||
18 | %blockquote= @comment.body | ||
19 | %p | ||
20 | Posted: | ||
21 | = @comment.published_at.strftime("%B #{@comment.published_at.day.ordinalize}, %Y at %-I:%M:%S%P") | ||
22 | %p= link_to "See the comment on the web", blog_url(@comment.blog, anchor: "comment-#{@comment.id}") | ||
diff --git a/app/views/comment_mailer/new_comment_email.text.erb b/app/views/comment_mailer/new_comment_email.text.erb new file mode 100644 index 0000000..e37046f --- /dev/null +++ b/app/views/comment_mailer/new_comment_email.text.erb | |||
@@ -0,0 +1,20 @@ | |||
1 | Four Island | ||
2 | =========== | ||
3 | |||
4 | A comment has been posted on <%= @comment.blog.title %> by the following user: | ||
5 | |||
6 | * Name: <%= @comment.username %> | ||
7 | * Email: <%= @comment.email %> | ||
8 | <% unless @comment.website.empty? %>* Website: <%= @comment.website %> | ||
9 | <% end %> | ||
10 | Here is the comment: | ||
11 | |||
12 | --- | ||
13 | |||
14 | <%= @comment.body %> | ||
15 | |||
16 | --- | ||
17 | |||
18 | Posted: <%= @comment.published_at.strftime("%B #{@comment.published_at.day.ordinalize}, %Y at %-I:%M:%S%P") %> | ||
19 | |||
20 | See the comment on the web: <%= blog_url(@comment.blog, anchor: "comment-#{@comment.id}") %> | ||
diff --git a/config/deploy.rb b/config/deploy.rb index cbac23c..05b137d 100644 --- a/config/deploy.rb +++ b/config/deploy.rb | |||
@@ -21,7 +21,7 @@ set :deploy_to, "/srv/www/thoughts" | |||
21 | # set :pty, true | 21 | # set :pty, true |
22 | 22 | ||
23 | # Default value for :linked_files is [] | 23 | # Default value for :linked_files is [] |
24 | append :linked_files, "config/database.yml", "config/secrets.yml", "config/lingo.yml", "config/akismet.yml" | 24 | append :linked_files, "config/database.yml", "config/secrets.yml", "config/lingo.yml", "config/akismet.yml", "config/mail.yml" |
25 | 25 | ||
26 | # Default value for linked_dirs is [] | 26 | # Default value for linked_dirs is [] |
27 | append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "public/uploads" | 27 | append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "public/uploads" |
diff --git a/config/environments/development.rb b/config/environments/development.rb index 8500f45..e683ebb 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb | |||
@@ -37,6 +37,7 @@ Rails.application.configure do | |||
37 | config.active_storage.service = :local | 37 | config.active_storage.service = :local |
38 | 38 | ||
39 | # Don't care if the mailer can't send. | 39 | # Don't care if the mailer can't send. |
40 | config.action_mailer.default_url_options = { host: 'localhost:3000' } | ||
40 | config.action_mailer.raise_delivery_errors = false | 41 | config.action_mailer.raise_delivery_errors = false |
41 | 42 | ||
42 | config.action_mailer.perform_caching = false | 43 | config.action_mailer.perform_caching = false |
diff --git a/config/environments/production.rb b/config/environments/production.rb index 182b74e..e814a66 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb | |||
@@ -66,7 +66,9 @@ Rails.application.configure do | |||
66 | # Set this to true and configure the email server for immediate delivery to raise delivery errors. | 66 | # Set this to true and configure the email server for immediate delivery to raise delivery errors. |
67 | # config.action_mailer.raise_delivery_errors = false | 67 | # config.action_mailer.raise_delivery_errors = false |
68 | 68 | ||
69 | config.action_mailer.default_url_options = { host: 'feffernoo.se' } | 69 | config.action_mailer.default_url_options = { host: 'www.fourisland.com' } |
70 | config.action_mailer.delivery_method = :smtp | ||
71 | config.action_mailer.smtp_settings = Rails.application.config_for(:mail)[:smtp_settings] | ||
70 | 72 | ||
71 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to | 73 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to |
72 | # the I18n.default_locale when a translation cannot be found). | 74 | # the I18n.default_locale when a translation cannot be found). |
diff --git a/config/mail.yml b/config/mail.yml new file mode 100644 index 0000000..3c88234 --- /dev/null +++ b/config/mail.yml | |||
@@ -0,0 +1,8 @@ | |||
1 | production: | ||
2 | smtp_settings: | ||
3 | address: "" | ||
4 | port: 25 | ||
5 | user_name: "" | ||
6 | password: "" | ||
7 | authentication: "" | ||
8 | openssl_verify_mode: "" | ||
diff --git a/test/mailers/comment_mailer_test.rb b/test/mailers/comment_mailer_test.rb new file mode 100644 index 0000000..996d230 --- /dev/null +++ b/test/mailers/comment_mailer_test.rb | |||
@@ -0,0 +1,7 @@ | |||
1 | require "test_helper" | ||
2 | |||
3 | class CommentMailerTest < ActionMailer::TestCase | ||
4 | # test "the truth" do | ||
5 | # assert true | ||
6 | # end | ||
7 | end | ||
diff --git a/test/mailers/previews/comment_mailer_preview.rb b/test/mailers/previews/comment_mailer_preview.rb new file mode 100644 index 0000000..20fc4e6 --- /dev/null +++ b/test/mailers/previews/comment_mailer_preview.rb | |||
@@ -0,0 +1,4 @@ | |||
1 | # Preview all emails at http://localhost:3000/rails/mailers/comment_mailer | ||
2 | class CommentMailerPreview < ActionMailer::Preview | ||
3 | |||
4 | end | ||