Skip to content

Commit

Permalink
Refactor SurveyMailer
Browse files Browse the repository at this point in the history
  • Loading branch information
Bojidarist committed Sep 9, 2021
1 parent 168e193 commit 3f75daf
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/controllers/surveys_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def create
end
end

SurveyMailer.with(username: current_user.username, survey: @survey).survey_created.deliver_later
SurveyMailer.with(survey: @survey).survey_created.deliver_later

redirect_to @survey
else
Expand Down
4 changes: 2 additions & 2 deletions app/mailers/survey_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ class SurveyMailer < ApplicationMailer
default from: "[email protected]"

def survey_created
@username = params[:username]
@survey = params[:survey]
mail(to: "[email protected]", subject: "New survey created by #{ @username }")
mail(to: "[email protected]",
subject: "New survey created by #{ @survey.user.username }")
end
end
2 changes: 1 addition & 1 deletion app/views/survey_mailer/survey_created.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<h1>The survey <%= @survey.question %> was created by <%= @username %></h1>
<h1>The survey <%= @survey.question %> was created by <%= @survey.user.username %></h1>

<h2>Answers:</h2>
<ul>
Expand Down
2 changes: 1 addition & 1 deletion app/views/survey_mailer/survey_created.text.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
The survey <%= @survey.question %> was created by <%= @username %>
The survey <%= @survey.question %> was created by <%= @survey.user.username %>

Answers:
<% @survey.answers.each do |answer| %>
Expand Down
2 changes: 1 addition & 1 deletion test/mailers/previews/survey_mailer_preview.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Preview all emails at https://localhost:3000/rails/mailers/survey_mailer
class SurveyMailerPreview < ActionMailer::Preview
def survey_created
SurveyMailer.with(username: User.first.username, survey: Survey.first).survey_created
SurveyMailer.with(survey: Survey.first).survey_created
end
end

0 comments on commit 3f75daf

Please sign in to comment.