views:

447

answers:

1

Hello, i'm trying to build a contact form in Rails 2.3.4. I'm using the jQuery Form plugin along with this (http://bassistance.de/jquery-plugins/jquery-plugin-validation/) for validations. Everything works in my development environment (mac os x snow leopard), the loading gif appears and on my log the email gets sent and the "request completed" notice shows. But on my production machine the loading gif just keeps going and the form doesn't get sent. I've waited as long as I could, nothing.

Here is my code:

/public/javascripts/application.js


 // client-side validation and ajax submit contact form 
 $('#contactForm').validate( {
  rules: {
   'email[name]': { required: true },
   'email[address]': {
    required: true,
    email: true
   },
   'email[subject]': {
    required: true
   },
   'email[body]': {
    required: true
   }
  },
  messages: {
   'email[name]': "Please enter your name.",
   'email[address]': "Please enter a valid email address.",
   'email[subject]': "Please enter a subject.",
   'email[body]': "Please enter a message."
  },
  submitHandler: function(form) {
   $(form).ajaxSubmit({
    dataType: 'script',
    beforeSend: function() {
     $(".loadMsg").show();
    }
   });
   return false;
  }  
 });

I'm using the submitHandler to send the actual ajaxSubmit. I added the "dataType: "script" and the "beforeSubmit" for the loading graphic.


  def send_mail
    if request.post?
      respond_to do |wants|
        ContactMailer.deliver_contact_request(params[:email])
        flash[:notice] = "Email was successfully sent."
        wants.js
      end
    end
  end

Everything works fine on development, but not in production. What am I missing or did wrong?

+1  A: 

I would check your production logs to see if possibly the Mailer isn't able to actually send the email. Several things I would check:

  • Did you define the mailer config in just your environments/development.rb and not also in environments/production.rb or in environment.rb?
  • Since its showing your 'loader', its unlikely that its not sending the correct JS files, but I would check to make sure its sending the correct versions if maybe you're caching your JS files.

You could also always run script/server production locally or switch your Passenger env locally to production to test it if its a hassle to check to check on your actual production servers.

I would also take the Mailer and move it out of the responds_to block:

  def send_mail
    if request.post?
      ContactMailer.deliver_contact_request(params[:email])
      respond_to do |wants|
        wants.js
      end
    end
  end
Kyle Daigle