about summary refs log tree commit diff stats
path: root/app
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2023-10-12 21:51:02 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2023-10-12 21:51:02 -0400
commit9ad3bca2ea475b709c8311ab25194e4578c1a0d9 (patch)
treeb60fa4048784bb36853d461fc6df14579a241534 /app
parent2022e18daab968ad49af9b3e59969ef1ed110436 (diff)
downloadthoughts-9ad3bca2ea475b709c8311ab25194e4578c1a0d9.tar.gz
thoughts-9ad3bca2ea475b709c8311ab25194e4578c1a0d9.tar.bz2
thoughts-9ad3bca2ea475b709c8311ab25194e4578c1a0d9.zip
Webmaster gets an email when a comment is posted
Diffstat (limited to 'app')
-rw-r--r--app/controllers/comments_controller.rb4
-rw-r--r--app/mailers/application_mailer.rb2
-rw-r--r--app/mailers/comment_mailer.rb7
-rw-r--r--app/views/comment_mailer/new_comment_email.html.haml22
-rw-r--r--app/views/comment_mailer/new_comment_email.text.erb20
5 files changed, 54 insertions, 1 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 @@
1class ApplicationMailer < ActionMailer::Base 1class ApplicationMailer < ActionMailer::Base
2 default from: 'from@example.com' 2 default from: 'no-reply@fourisland.com'
3 layout 'mailer' 3 layout 'mailer'
4end 4end
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 @@
1class 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
7end
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 @@
1Four Island
2===========
3
4A 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 %>
10Here is the comment:
11
12---
13
14<%= @comment.body %>
15
16---
17
18Posted: <%= @comment.published_at.strftime("%B #{@comment.published_at.day.ordinalize}, %Y at %-I:%M:%S%P") %>
19
20See the comment on the web: <%= blog_url(@comment.blog, anchor: "comment-#{@comment.id}") %>