I am using RJS with Prototype and I am trying to replace HTML code while the RoR Mailer system sends an e-mail. In few words I aim to show a .gif image near a button while the browser load.
In my app/views/users/reset.js.rjs file I have this code:
page.replace(:action_button, system_image_loading_tag)
page.redirect_to( :root )
In my app/controllers/*users_controller.rb* I have this code:
def reset
respond_to do |format|
UsersMailer.confirm_reset(user).deliver
format.js
end
end
Submitting the related form I must wait that the e-mail has been sent and then the browser will redirect to the root path. So, if I want avoid to loose this time, what I can do? What is the best way to do it?
Sounds like you’re having a problem similar to this user. If you don’t want to have to wait for the mail to be delivered before your Controller renders the action, try moving the email delivery to the background. If you’ve already got a system for running background jobs, great! If not, these instructions for using DelayedJob with ActionMailer seem pretty straight-forward, even though I haven’t personally used DelayedJob.