From 26a7339889929025495df59776d1a33ca19c77ae Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Fri, 13 Oct 2023 13:18:18 -0400 Subject: Pending comments also send you an email now --- app/controllers/comments_controller.rb | 2 ++ app/mailers/comment_mailer.rb | 6 ++++++ .../new_pending_comment_email.html.haml | 22 ++++++++++++++++++++++ .../new_pending_comment_email.text.erb | 19 +++++++++++++++++++ 4 files changed, 49 insertions(+) create mode 100644 app/views/comment_mailer/new_pending_comment_email.html.haml create mode 100644 app/views/comment_mailer/new_pending_comment_email.text.erb (limited to 'app') diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index c66365b..a444dba 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -46,6 +46,8 @@ class CommentsController < ApplicationController if @comment.status == :published CommentMailer.with(comment: @comment).new_comment_email.deliver_later + else + CommentMailer.with(comment: @comment).new_pending_comment_email.deliver_later end else flash.alert = "Error posting comment." diff --git a/app/mailers/comment_mailer.rb b/app/mailers/comment_mailer.rb index 363875a..e72b17d 100644 --- a/app/mailers/comment_mailer.rb +++ b/app/mailers/comment_mailer.rb @@ -4,4 +4,10 @@ class CommentMailer < ApplicationMailer @admin = User.first # this is weird mail(to: @admin.email, subject: "[Four Island] Comment on #{@comment.blog.title}") end + + def new_pending_comment_email + @comment = params[:comment] + @admin = User.first # this is weird + mail(to: @admin.email, subject: "[Four Island] Pending comment on #{@comment.blog.title}") + end end diff --git a/app/views/comment_mailer/new_pending_comment_email.html.haml b/app/views/comment_mailer/new_pending_comment_email.html.haml new file mode 100644 index 0000000..d3f7dca --- /dev/null +++ b/app/views/comment_mailer/new_pending_comment_email.html.haml @@ -0,0 +1,22 @@ +%p + A new comment has been posted on + = link_to @comment.blog.title, @comment.blog + that is pending moderation. +%p The details of the user that posted it: +%ul + %li + Name: + = @comment.username + %li + Email: + = @comment.email + - unless @comment.website.empty? + %li + Website: + = @comment.website +%p Here is the comment: +%blockquote= @comment.body +%p + Posted: + = @comment.created_at.strftime("%B #{@comment.created_at.day.ordinalize}, %Y at %-I:%M:%S%P") +%p= link_to "Go to the admin panel", pending_admin_comments_url diff --git a/app/views/comment_mailer/new_pending_comment_email.text.erb b/app/views/comment_mailer/new_pending_comment_email.text.erb new file mode 100644 index 0000000..787d6b8 --- /dev/null +++ b/app/views/comment_mailer/new_pending_comment_email.text.erb @@ -0,0 +1,19 @@ +A comment has been posted on <%= @comment.blog.title %> that is pending moderation. + +The details of the user that posted it: + +* Name: <%= @comment.username %> +* Email: <%= @comment.email %> +<% unless @comment.website.empty? %>* Website: <%= @comment.website %> +<% end %> +Here is the comment: + +--- + +<%= @comment.body %> + +--- + +Posted: <%= @comment.created_at.strftime("%B #{@comment.created_at.day.ordinalize}, %Y at %-I:%M:%S%P") %> + +Go to the admin panel: <%= pending_admin_comments_url %> -- cgit 1.4.1