0

私はこのポートフォリオ サイトを持っていますが、最初のタブの連絡先フォームが機能していませんが、2 番目のタブのフォームは機能しています。おそらくルーティングの問題だと思います。ルーティングファイルにあるものは次のとおりです。

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 に答える