Jump to content

The ultimate community for Ruby on Rails developers.


Photo

Multiple emails get sent when submitting form

email devise ruby rails form

  • Please log in to reply
No replies to this topic

#1 amjadinzi

amjadinzi

    Passenger

  • Members
  • 1 posts

Posted 04 April 2014 - 10:43 AM

 

I am newbie and following tutorials i put up my first application and currently hosting on free heroku dyno. The issue is that some time the form is not getting posted and I got into habit of stopping it using the browser stop button and then posting it again. I have now realized that my email reputation has dropped to 40% (sendgrid), the reason being the same email sent to same address multiple times once i resent the form once it failed or i stopped start and resubmit form. 

 

The issue is that if after filling form and pressing submit followed by quick pressing of browser stop and quick repition of two actions i.e (submit stop, submit stop), the email gets sent each time as long as i keep doing it. I tried the doing the same on devise sign up form and i couldn't make it send more than one email. I am using captcha (humanizer) on the form but if any bot could quickly do submit /stop repeatedly to send massive emails than it just defeat the purpose of using captcha. What should i do to make sure that email gets sent only once like it does in devise sign_up form which sends one confirmation email.

 

To send email after save i am using the following code in the create action.

def create
@job_post = JobPost.new(params[:job_post])
@job_post.jobuuid = SecureRandom.hex(7)

if @job_post.save
if user_signed_in?
@job_post.update_attribute(:user_id, current_user.id) 
else
@job_post.update_attribute(:user_id, 1) 
end
# Handle a successful save.
# Email to JobPoster
JobMailer.jobposting_acknowledgment(@job_post).deliver
# Email to Admin
JobMailer.jobposting_adminnotification(@job_post).deliver
flash[:notice] = "Job posting is received and is being manually reviewed."
redirect_to root_path
else
render 'new'
end end

Thanks

 






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users