I'm working on creating a basic survey app to better learn Rails.
Right now I'm working on learning how to send emails. I've gotten it to work, but now I'm running into a scenario where I send out a lot of duplicate emails. The duplicates are coming out because I'm only checking for a status of Submitted
on PUT
and then sending out the email.
def update
p params
# unless signed_in?
# redirect_to signin_path
# end
respond_to do |format|
if @survey.update(survey_params)
@survey.check_email
if @survey.status == "Submitted"
SurveyMailer.survey_created(@survey).deliver
end
format.html { redirect_to @survey, notice: 'Survey was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: 'edit' }
format.json { render json: @survey.errors, status: :unprocessable_entity }
end
end
end
What's the best way to check/track which emails for a survey I've sent it out to? Basically some sort of "if user has not been notified that a survey has been shared with them, send it out, otherwise don't"