0

我有一个弹出式登录表单,它通过 jQuery Ajax 在表单正文中显示错误消息。它在我的本地环境(PostGreSQL、WEBbrick)上运行良好,但在 Heroku 上运行良好。在 Heroku 上,用户被重定向到仅显示错误消息的新页面,即 {"error":"Invalid Email Address: testing@test.com"}

页面上其实有两种注册表单,一种是通过jQuery Dialog弹出的,另一种是嵌入到页面中的。谢谢你的帮助。

这是控制器: class MailingListController < ApplicationController

 respond_to :json

 def create
   gb = Gibbon.new(Settings.mailchimp.api_key)
   res = gb.list_subscribe({:id => Settings.mailchimp.list_id, :email_address => params[:email]})
   if res == true
     render(:json => {:body => "okay"})
   else
     render(:json => {:error => res["error"]})
   end
 rescue
   render(:json => {:error => "Fatal Error"})
  end
end

这是js(我知道,重复的代码,我只是想让它工作):

  // Mailing List Watcher
 var mailingList2 = $("#mailing-list2");
 if ( mailingList2.length ) {
   mailingList2
     .live("completed", function(e){
     })
     .live("success", function(e){
       var that = this;
       $.cookie("mailingListSubmitted", "true", {expires: 7});
       if(mailingList2.find("#mailing-list2 #status2").length == 0){
         mailingList2
           .find("form input[type='text']")
           .after($("<div></div>").attr({id : "status2"}))
       }
       mailingList2
         .find("form input[type='text']")
           .attr("disabled", true)
           .fadeOut(5000);
       $("#mailing-list2 #status2")
         .text("Email submitted successfully!")
         .effect("highlight", { }, 1000);
     })
     .live("failure", function(e, error){
      if(mailingList2.find("#mailing-list2 #status2").length == 0){
         mailingList2
           .find("form input[type='text']")
           .after($("<div></div>").attr({id : "status2"}))
       }
       $("#mailing-list2 #status2")
         .text(error)
         .effect("highlight", {}, 1000);
     })
     .live("submittal", function(e, emailAddress){
       if ( emailAddress == "" || emailAddress == null ) {
         $(this).trigger("failure", ["You need to specify an email address!"])
         return false;
       }
       var token = $.token();
       $.post("/mailing_list", {email: emailAddress, authenticity_token: token}, function(response, status, xhr){
         if(response.error){
           $(mailingList2).trigger("failure", ["An error occurred: " + response.error]);
         } else {
           $(mailingList2).trigger("success");
         }
       }, "json")
       .error(function(){
         $(mailingList2).trigger("failure", ["An error occurred. Please try again in a few minutes."]);
       });
     });


   mailingList2.find("form").submit(function(){
     emailAddress = mailingList2.find("input[name='email']").val();
     $(mailingList2).trigger("submittal", [emailAddress]);
     return false;
   });

   var mlSetting = $.cookie("mailingListSubmitted");
   if ( mlSetting == "true" ) {
     mailingList2.remove();
   }
 }

 // Mailing List Watcher
 var mailingList = $("#mailing-list");
 if ( mailingList.length ) {
   mailingList
     .live("completed", function(e){
     })
     .live("success", function(e){
       var that = this;
       $.cookie("mailingListSubmitted", "true", {expires: 7});
       if(mailingList.find("#status").length == 0){
         mailingList
           .find("form input[type='text']")
           .after($("<div></div>").attr({id : "status"}))
       }
       mailingList
         .find("form input[type='text']")
           .attr("disabled", true)
           .fadeOut(5000);
       $("#status")
         .text("Email submitted successfully!")
         .effect("highlight", { }, 1000);
     })
     .live("failure", function(e, error){
      if(mailingList.find("#status").length == 0){
         mailingList
           .find("form input[type='text']")
           .after($("<div></div>").attr({id : "status"}))
       }
       $("#status")
         .text(error)
         .effect("highlight", {}, 1000);
     })
     .live("submittal", function(e, emailAddress){
       if ( emailAddress == "" || emailAddress == null ) {
         $(this).trigger("failure", ["You need to specify an email address!"])
         return false;
       }
       var token = $.token();
       $.post("/mailing_list", {email: emailAddress, authenticity_token: token}, function(response, status, xhr){
         if(response.error){
           $(mailingList).trigger("failure", ["An error occurred: " + response.error]);
         } else {
           $(mailingList).trigger("success");
         }
       }, "json")
       .error(function(){
         $(mailingList).trigger("failure", ["An error occurred. Please try again in a few minutes."]);
       });
     });


   mailingList.find("form").submit(function(){
     emailAddress = mailingList.find("input[name='email']").val();
     $(mailingList).trigger("submittal", [emailAddress]);
     return false;
   });

   var mlSetting = $.cookie("mailingListSubmitted");
   if ( mlSetting == "true" ) {
     mailingList.remove();
   }
}
4

2 回答 2

0

答案就在这里,虽然我之前读过这篇文章,但还是尝试了几次才能让它发挥作用:https ://devcenter.heroku.com/articles/pgbackups#exporting-via-a-backup

于 2012-08-20T21:46:27.053 回答
0

您的 environment/production.rb 未正确配置为发送电子邮件。您需要确保将其设置为作为您实际拥有的域发送电子邮件。RailsHeroku都有关于这个主题的好文章。

于 2012-08-14T22:23:19.917 回答