Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

Hi all, I’m trying to set up an email form that uses Google’s smtp servers and ActionMailer that sends emails on form submission. I should start out by saying that this works fine in development on my local machine and in production on Heroku, but not from my digital ocean droplet.
Basically, when I submit the form, it sits for 30 seconds and returns an internal server error. I suspect the problem is in ActionMailer because if I remove the ActionMailer code from my controller, the form submits as expected (but obviously sends no email).
Code:
routes.rb
resources :home_page, only: :index
match '/email' => 'home_page#send_email_form', as: :email_form, via: :post
root :to => 'home_page#index'
home_page_controller.rb
def send_email_form
@message = Message.new(params[:message])
if @message.valid?
ReferralMailer.message_confirmation(@message).deliver
ReferralMailer.send_mail(@message).deliver
respond_to do |format|
format.html{redirect_to root_path}
format.js
end
else
respond_to do |format|
format.html{redirect_to root_path}
format.js
end
end
end
_form.html.erb
<%= form_for @message, url: email_form_path, remote:true do |f| %>
<%= f.label :name, class: 'label' %>
<%= f.text_field :name, class: 'input', placeholder: "Enter your name" %>
<%= f.label :email, class: 'label' %>
<%= f.text_field :email, class: 'input', placeholder: "Enter your email" %>
<%= f.label :phone, class: 'label' %>
<%= f.text_field :phone, class: 'input', placeholder: "Enter your phone number"%>
<%= f.label :message, class: 'label' %>
<%= f.text_area :body, class: 'input', placeholder: "Enter a brief message"%>
<%=f.submit 'Send Message', id:'submit', class: "margin-top-20 alt-button button radius large" %>
<% end %>
client-side-javascript
$('#new_message').submit(function(e){
if($(this).valid()){
$('.form-header').addClass('submitting');
$('#submit').prop('disabled', 'disabled');
$('#spinner').show();
var target = document.getElementById('spinner');
var opts = {
lines: 13, // The number of lines to draw
length: 10, // The length of each line
width: 10, // The line thickness
radius: 20, // The radius of the inner circle
corners: 1, // Corner roundness (0..1)
rotate: 0, // The rotation offset
direction: 1, // 1: clockwise, -1: counterclockwise
color: '#000', // #rgb or #rrggbb or array of colors
speed: 1, // Rounds per second
trail: 60, // Afterglow percentage
shadow: false, // Whether to render a shadow
hwaccel: false, // Whether to use hardware acceleration
className: 'spinner', // The CSS class to assign to the spinner
zIndex: 2e9, // The z-index (defaults to 2000000000)
top: '50%', // Top position relative to parent
left: '50%' // Left position relative to5 parent
};
var spinner = new Spinner(opts).spin(target);
}
else{
$(this).prev().prev().addClass('label-error');
e.preventDefault();
}
});
send_email_form.js.erb
$(document).ready(function(){
var form=$('#new_message');
var form_header=$('.form-header');
<% if @message.valid? %>
form_header.removeClass('submitting');
$('#spinner').hide();
form.children().hide();
form.append('<%= j render(:partial=>"confirmation")%>');
<%end%>
});
Is there anything special I need to set up in unicorn or in nginx to make the AJAX request work? Also FWIW, if I remove the remote:true from my form_for tag, it doesn’t redirect either which leads to believe that the problem is in the ActionMailer somewhere.
Anyone have any ideas? Thanks so much!
3630316526124b4190e628cd69be1e
6a2e133a62fe4859920f9233303d8c
c6fa584e45c14c21ae44129dfe5743
Maria Smith
819167b5336c456e9ad38395fec1c5
bitandmap
e13d124f55014cf1a5bfd586997890
eea0a4f7eca348d58775fb7c7015fc
1636b10487fe4ab5b1e3bc483fd84f
e3002a14a547406799fe27a6abf211
5f21ced7a9dd4fe7af83c7412c563f
David Sen