0

我有这个投资组合网站,第一个标签的联系表格不起作用,而第二个标签的表格起作用。我怀疑这可能是路由问题。这是我的路由文件中的内容:

Inspired::Application.routes.draw do
  get "pages/home"
  get "pages/about_us"
  get "pages/web_design"
  get "pages/portfolio"
  get "pages/contact"
  get "pages/new"

  match 'contact'    => 'pages#new',       :as => 'contact',    :via => :get
  match 'contact'    => 'pages#create',    :as => 'contact',    :via => :post
  match 'contactrfp' => 'pages#createrfp', :as => 'contactrfp', :via => :post

  root :to => 'pages#home'

这是控制器的外观:

def contact
  @message    = Message.new
  @messagerfp = Messagerfp.new
end

def create
  @message = Message.new(params[:message])
  if @message.valid?
    NotificationsMailer.new_message(@message).deliver
    redirect_to(root_path, :notice => "Message was successfully sent.")
  else
    #flash.now.alert = "Please fill all fields."
    #render :new
  end
end

def createrfp
  @messagerfp = Messagerfp.new(params[:messagerfp])
  if @messagerfp.valid?
    NotificationsMailer.new_messagerfp(@messagerfp).deliver
    redirect_to(root_path, :notice => "Message was successfully sent.")
  else
    #flash.now.alert = "Please fill all fields."
    #render :new
  end
end

让我知道您是否需要更多信息。我正在客户端进行所有验证,包括使用 jQuery 的实际提交提前谢谢!

这是视图:

                    <script type="text/javascript">
                  $(document).ready(function() {
                  $('#navhorisontell ul li a:eq(4)').addClass('selected');

                  /* START TAB STUFF */

                    $(".tab_content").hide(); //Hide all content
                    $("ul.tabs li:first").addClass("active").show(); //Activate first tab
                    $(".tab_content:first").show(); //Show first tab content

                    //On Click Event
                    $("ul.tabs li").click(function() {

                        $("ul.tabs li").removeClass("active"); //Remove any "active" class
                        $(this).addClass("active"); //Add "active" class to selected tab
                        $(".tab_content").hide(); //Hide all tab content

                        var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
                        $(activeTab).fadeIn(); //Fade in the active ID content
                        return false;
                    });

                    /*END TAB STUFF */



                    var name = $("#contactname").val();
                var email = $("#email").val();
                var message = $("#subject").val();
                var age = $("#message").val();
                   var datastr = 'name=' + name + 'email=' + email + '&subject=' + message;

                    allclear = null;



                  $('#submit24').click(function(){

                  allclear = true;
                  $('.errors').html('');
                  if($('#name').val() == ''){
                    $('.errors').append('<p style="color:#cc0000; font-weight:bold;"><span class="sup">*</span>Please fill in your name.</p>');
                    allclear = false;
                  }

                    if($('#email').val() == ''){
                    $('.errors').append('<p style="color:#cc0000; font-weight:bold;"><span class="sup">*</span>Please fill in your email address.</p>');
                    allclear = false;
                  }

                    if($('#location').val() == ''){
                    $('.errors').append('<p style="color:#cc0000; font-weight:bold;"><span class="sup">*</span>Please fill in your location.</p>');
                    allclear = false;
                  }


                    if($('#howfound').val() == ''){
                    $('.errors').append('<p style="color:#cc0000; font-weight:bold;"><span class="sup">*</span>Please fill in how you found us.</p>');
                    allclear = false;
                  }




                    if(allclear == false){
                        window.location.href = '#col1';
                    }



                  if(allclear == true){




                  $('.clear').html('<br /><img src="/assets/ajax-loader.gif"/>');
                  $('.rfp').submit();




                  function allcomplete(){
                scroll(0,0);
                $('.errors').html('');
                $("#tab1").html("<p>Thanks for your inquiry. We'll contact you in 24-48 hours regarding your request! </p>");
                }
                setTimeout(allcomplete,1000);
                     //alert('hi');


                }

                /*
                function sendemail(){
                $.ajax({
                type: "POST",
                url: "/assets/mail.php",
                //data: ({email : $("#email").val(), message: 'Name: ' + $("#name").val() + '\r' + 'email: ' + $('#email').val() + '\r' + 'phone: ' + $('#phone').val() + '\r' + 'Location: ' + $('#location').val() + '\r' + 'Business Name: ' + $('#bizname').val() + '\r' + 'Business Description: ' + $('#bizdesc').val() + '\r' + 'phone: ' + $('#phone').val()}),
                data: ({email : $("#email").val(), message: 'Name: ' + $("#name").val() + '\r' + 'email: ' + $('#email').val() + '\r' + 'phone: ' + $('#phone').val() + '\r' + 'Location: ' + $('#location').val() + '\r' + 'Business Name: ' + $('#bizname').val() + '\r' + 'Business Description: ' + $('#bizdesc').val() + '\r' + 'Have website: ' + $('#website').val() + '\r' + 'Services interested in: ' + $('#services').val() + '\r' + 'Additional details: ' + $('#adddetails').val() + '\r' + 'Budget: ' + $('#budget').val() + '\r' + 'How did you find us: ' + $('#howfound').val()}),
                cache: false,
                 error: function () {

                             //alert('did not go thru');
                                $('.errors').append('<p style="color:#cc0000; font-weight:bold;"><span class="sup"></span>Oops, there seems to be a problem sending in your request. Please try again later or contact us at 312.612.0696</p>');
                            },
                success: function(html){
                //$("#response").fadeIn("slow");
                scroll(0,0);
                $('.errors').html('');
                $("#tab1").html("<p>Thanks for your inquiry. We'll contact you in 24-48 hours regarding your request! </p>");
                //setTimeout('$("#response").fadeOut("slow")',2000);
                //alert('mail sent');
                }
                });
                }
                */
                    });





                    //FORM 2
                    //FORM 2
                    //FORM 2
                    //FORM 2
                    //FORM 2
                    //FORM 2
                    //FORM 2
                    //FORM 2
                    //FORM 2
                    //FORM 2
                    //FORM 2
                    //FORM 2
                    //FORM 2



                      $('#submit2').click(function(){

                  allclear2 = true;
                  $('.errors2').html('');

                  if($('#name2').val() == ''){
                    $('.errors2').append('<p style="color:#cc0000; font-weight:bold;"><span class="sup">*</span>Please fill in your name.</p>');
                    allclear2 = false;
                  }

                    if($('#email2').val() == ''){
                    $('.errors2').append('<p style="color:#cc0000; font-weight:bold;"><span class="sup">*</span>Please fill in your email address.</p>');
                    allclear2 = false;
                  }



                    if($('#bizdesc2').val() == ''){
                    $('.errors2').append('<p style="color:#cc0000; font-weight:bold;"><span class="sup">*</span>Please fill in a message.</p>');
                    allclear2 = false;
                  }




                    if(allclear2 == false){
                        window.location.href = '#col2';
                    }



                  if(allclear2 == true){
                  //alert('hi');
                  $('.clear2').html('<br /><img src="/assets/ajax-loader.gif"/>');
                  $('.rfp2').submit();




                  function allcomplete2(){
                  scroll(0,0);
                $('.errors2').html('');
                $("#tab2").html("<p>Successfully sent. Thanks for your inquiry! </p>");
                }
                setTimeout(allcomplete2,1000);

                }








                    });



                  });
                </script>

                <!--START CONTENT -->






                <div id="col1">



                <!-- CONTACT FORM -->

                <p> <span class="opening">Get in Touch!</span></p>



                <ul class="tabs">
                    <li><a href="#tab1">Request for Proposal</a></li>
                    <li><a href="#tab2">Other Inquiries</a></li>
                    <li><a href="#tab3">Refer a Friend</a></li>
                    <li><a href="#tab4">Contact Info</a></li>
                </ul>

                <div class="tab_container">
                    <div id="tab1" class="tab_content">






                        <div class="form">



                            <%= form_for @messagerfp, :html => { :class => "rfp"}, :remote => true, :url => contactrfp_path do |form| %>

                      <p>Your Name<span class="sup">*</span></p>
                      <%= form.text_field :name, :id => "name" %>



                      <br /><br />
                    <p>Your Email<span class="sup">*</span></p>
                      <%= form.text_field :email, :id => "email" %>




                <br /><br />
                    <p>Your Location<span class="sup">*</span></p>
                    <%= form.text_field :location, :id => "location" %>


                    <br /><br />
                    <p>How did you find us?<span class="sup">*</span></p>
                    <%= form.text_field :howfound, :id => "howfound" %>


                <div class="clear" style="margin-bottom:20px; cursor:pointer;"><br />
                    <!--<span class="button" id="submit2"><span>Submit</span></span>-->
                         <%= form.submit "Send", :class => "button", :id => "submit24" %>


                    </div>
                <% end %>






                    <!--<form class="rfp">
                    <p>Your Name<span class="sup">*</span></p>
                    <input type="name" tabindex="1" class="medium" value="" id="name" name="input_1">
                    <br /><br />
                    <p>Your Email<span class="sup">*</span></p>
                    <input type="mail" tabindex="1" class="medium" value="" id="email" name="input_1">
                    <br /><br />
                    <p>Phone and/or Skype ID (optional)</p>
                    <input type="subject" tabindex="1" class="medium" value="" id="phone" name="input_1">
                    <br /><br />
                    <p>Your Location<span class="sup">*</span></p>
                    <input type="text" tabindex="1" class="medium" value="" id="location" name="input_1">
                    <br /><br />
                    <p><span class="bold larger">Your Business</span></p>
                    <br />
                    <p>Business name and industry</p>
                    <input type="text" tabindex="1" class="medium" value="" id="bizname" name="input_1">
                    <br /><br />
                    <p>Brief description of your business or organization</p>
                    <textarea type="text" tabindex="1" class="medium" value="" id="bizdesc" name="input_1" rows="10" cols="29"></textarea>
                    <br /><br />

                        <p>Do you currently have a website?</p>
                    <input type="text" tabindex="1" class="medium" value="" id="website" name="input_1">
                    <br /><br />
                    <p><span class="bold larger">Your Project</span></p>
                    <br />
                    <p>Briefly list the services that you're interested in?</p>
                    <textarea type="text" tabindex="1" class="medium" value="" id="services" name="input_1" rows="10" ></textarea>
                    <br /><br />
                    <p>Additional details about your project</p>
                    <textarea type="text" tabindex="1" class="medium" value="" id="adddetails" name="input_1" rows="10" ></textarea>
                    <br /><br />


                    <p>Project Budget (USD)</p>

                    <select tabindex="11" class="medium gfield_select" id="budget" name="input_17"><option selected="selected" value="$1,000 - $5,000">$1,000 - $5,000</option><option value="$5,000 - $10,000">$5,000 - $10,000</option><option value="$10,000 - $15,000">$10,000 - $15,000</option><option value="&gt; $15,000">&gt; $15,000</option></select>
                    <br /><br />
                    <p><span class="bold larger">Get in Touch</span></p>
                    <br />
                    <p>How did you find us?<span class="sup">*</span></p>
                    <input type="text" tabindex="1" class="medium" value="" id="howfound" name="input_1">
                    <br /><br />
                    <div class="clear" style="margin-bottom:20px; width:100px; float:right; cursor:pointer;">
                    <span class="button" id="submit"><span>Submit</span></span>
                    </div>
                    </form>-->
                    </div>
                    <br />

                    <div class="errors">

                    </div>




                    </div>
                    <div id="tab2" class="tab_content">



                      <div class="form">
                    <!--<form class="rfp2">
                    <p>Your Name<span class="sup">*</span></p>
                    <input type="name" tabindex="1" class="medium" value="" id="name2" name="input_1">
                    <br /><br />
                    <p>Your Email<span class="sup">*</span></p>
                    <input type="mail" tabindex="1" class="medium" value="" id="email2" name="input_1">
                    <br /><br />
                    <p>Message<span class="sup">*</span></p>
                    <textarea type="text" tabindex="1" class="medium" value="" id="bizdesc2" name="input_1" rows="10" cols="29"></textarea>
                    <br /><br />



                    <div class="clear2" style="margin-bottom:20px; width:100px; float:right; cursor:pointer;">
                    <span class="button" id="submit2"><span>Submit</span></span>
                    </div>
                    </form>-->

                    <%= form_for @message, :html => { :class => "rfp2"}, :remote => true, :url => contact_path do |form| %>

                      <p>Your Name<span class="sup">*</span></p>
                      <%= form.text_field :name, :id => "name2" %>



                      <br /><br />
                    <p>Your Email<span class="sup">*</span></p>
                      <%= form.text_field :email, :id => "email2" %>




                <br /><br />
                    <p>Message<span class="sup">*</span></p>
                    <%= form.text_area :body, :style => "resize:none;", :id => "bizdesc2" %>


                <div class="clear2" style="margin-bottom:20px; cursor:pointer;"><br />
                    <!--<span class="button" id="submit2"><span>Submit</span></span>-->
                         <%= form.submit "Send", :class => "button", :id => "submit2" %>


                    </div>
                <% end %>






                        <br />

                    <div class="errors2">

                    </div>








                    </div>
                    </div>
4

1 回答 1

0

查看您网站上的代码,这两个表单当前都提交给“/contact”。这不是你想要的。您的路线设置不正确。

第一个表单失败,因为您要发布params[:messagerfp]到 PagesController#create,它希望params[:message]构建一个Message对象。结果,@message无效,因此不会发送电子邮件。

于 2012-11-04T10:14:47.747 回答