Skip to content

Commit

Permalink
mailer for Operation entity added, feature of sending notifications a…
Browse files Browse the repository at this point in the history
…dded to users#update and destroy services
  • Loading branch information
alex223125 committed Sep 13, 2022
1 parent 1822438 commit fdd2e65
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 0 deletions.
Empty file modified app/jobs/application_job.rb
100644 → 100755
Empty file.
10 changes: 10 additions & 0 deletions app/mailers/action_notification_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class ActionNotificationMailer < ApplicationMailer
default from: "[email protected]"

def action_notification_email
@operation = params[:operation]
mail(to: @operation.user, subject: "Action has been taken")
end


end
Empty file modified app/mailers/application_mailer.rb
100644 → 100755
Empty file.
9 changes: 9 additions & 0 deletions app/models/operation.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
class Operation < ApplicationRecord

after_commit :notify, on: :create

def notify
ActionNotificationMailer.with({operation: self})
.action_notification_email
.deliver_now
end

end
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
</head>
<body>
<h1>Hello <%= @operation.user %></h1>
<p>
This is a message that action '<%= @operation.action %>' has been taken.
</p>
<p> Have a good day! </p>

</body>
</html>
Empty file modified app/views/layouts/mailer.html.erb
100644 → 100755
Empty file.
Empty file modified app/views/layouts/mailer.text.erb
100644 → 100755
Empty file.
5 changes: 5 additions & 0 deletions spec/mailers/action_notification_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require "rails_helper"

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

end

0 comments on commit fdd2e65

Please sign in to comment.