2016-10-13 6 views
0

私は連絡フォームを持っています。連絡フォームでは、ユーザーが自分の情報を送信して、私はサイトの管理者に送信することになっています。しかし、2つの電子メールは、管理者に送信される代わりに、1複数の挿入が行われているため、複数のメールが送信されています。

`` `

Parameters: {"utf8"=>"✓", "authenticity_token"=>"rJr/Z9zM21HhKhiQ0vw2afHKkTchUgDAxnvm13s3pD3jb8Elu/B65pHN2BUTUCwLauowgOum4JdyGeNdCsi3QQ==", "contact"=>{"name"=>"vamsi gates", "mobile"=>"07639817688", "email"=>"[email protected]", "requirement"=>"hello, my name is bamsi"}, "commit"=>"submit"} 
    (0.2ms) BEGIN 
    Contact Exists (0.6ms) SELECT 1 AS one FROM "contacts" WHERE "contacts"."name" = $1 AND "contacts"."mobile" = $2 AND "contacts"."requirement" = $3 AND "contacts"."email" = $4 LIMIT $5 [["name", "vamsi gates"], ["mobile", "07639817688"], ["requirement", "hello, my name is bamsi"], ["email", "[email protected]"], ["LIMIT", 1]] 
Started POST "/contacts" for 127.0.0.1 at 2016-10-13 13:20:03 +0530 
Processing by ContactsController#create as JS 
    SQL (2.2ms) INSERT INTO "contacts" ("name", "mobile", "email", "requirement", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id" [["name", "vamsi gates"], ["mobile", "07639817688"], ["email", "[email protected]"], ["requirement", "hello, my name is bamsi"], ["created_at", 2016-10-13 07:50:03 UTC], ["updated_at", 2016-10-13 07:50:03 UTC]] 
    Parameters: {"utf8"=>"✓", "authenticity_token"=>"rJr/Z9zM21HhKhiQ0vw2afHKkTchUgDAxnvm13s3pD3jb8Elu/B65pHN2BUTUCwLauowgOum4JdyGeNdCsi3QQ==", "contact"=>{"name"=>"vamsi gates", "mobile"=>"07639817688", "email"=>"[email protected]", "requirement"=>"hello, my name is bamsi"}, "commit"=>"submit"} 
    (0.2ms) BEGIN 
    Contact Exists (0.5ms) SELECT 1 AS one FROM "contacts" WHERE "contacts"."name" = $1 AND "contacts"."mobile" = $2 AND "contacts"."requirement" = $3 AND "contacts"."email" = $4 LIMIT $5 [["name", "vamsi gates"], ["mobile", "07639817688"], ["requirement", "hello, my name is bamsi"], ["email", "[email protected]"], ["LIMIT", 1]] 
    SQL (0.5ms) INSERT INTO "contacts" ("name", "mobile", "email", "requirement", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id" [["name", "vamsi gates"], ["mobile", "07639817688"], ["email", "[email protected]"], ["requirement", "hello, my name is bamsi"], ["created_at", 2016-10-13 07:50:03 UTC], ["updated_at", 2016-10-13 07:50:03 UTC]] 
    (51.0ms) COMMIT 
    Rendering guest_mailer/query_email.html.erb within layouts/mailer 
    Rendered guest_mailer/query_email.html.erb within layouts/mailer (0.5ms) 
GuestMailer#query_email: processed outbound mail in 8.0ms 
    (81.0ms) COMMIT 
    Rendering guest_mailer/query_email.html.erb within layouts/mailer 
    Rendered guest_mailer/query_email.html.erb within layouts/mailer (0.1ms) 
GuestMailer#query_email: processed outbound mail in 7.1ms 
Sent mail to [email protected], [email protected], [email protected] (20368.0ms) 
Date: Thu, 13 Oct 2016 13:20:03 +0530 
From: [email protected] 
To: [email protected], 
[email protected], 
[email protected] 
Message-ID: <[email protected]> 
Subject: We have a new lead from vamsi gates 
Mime-Version: 1.0 
Content-Type: text/html; 
charset=UTF-8 
Content-Transfer-Encoding: 7bit 

<!DOCTYPE html> 
<html> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <style> 
     /* Email styles need to be inline */ 
    </style> 
    </head> 

    <body> 
    <!DOCTYPE html> 
<html lang="en"> 
    <head> 
     <meta charset="utf-8"> 
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css"> 
     <link href='https://fonts.googleapis.com/css?family=Roboto+Slab:400,300,700' rel='stylesheet' type='text/css'> 
     <link href='https://fonts.googleapis.com/css?family=Roboto+Slab:400,300,700' rel='stylesheet' type='text/css'> 
     <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, target-densitydpi=device-dpi, user-scalable=0"> 
     <title>New enquiry for digifutura</title> 
    </head> 
    <body> 
    Name: vamsi gates <br> 
    Mobile: 07639817688 <br> 
    Email: [email protected] <br> 
    Requirement brief: <br> 
    hello, my name is bamsi 
    </body> 
    </html> 


    </body> 
</html> 

    Rendering contacts/create.js.erb 
Sent mail to [email protected], [email protected], [email protected] (20346.5ms) 
Date: Thu, 13 Oct 2016 13:20:03 +0530 
From: [email protected] 
To: [email protected], 
[email protected], 
[email protected] 
Message-ID: <[email protected]> 
Subject: We have a new lead from vamsi gates 
Mime-Version: 1.0 
Content-Type: text/html; 
charset=UTF-8 
Content-Transfer-Encoding: 7bit 

<!DOCTYPE html> 
<html> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <style> 
     /* Email styles need to be inline */ 
    </style> 
    </head> 

    <body> 
    <!DOCTYPE html> 
<html lang="en"> 
    <head> 
     <meta charset="utf-8"> 
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css"> 
     <link href='https://fonts.googleapis.com/css?family=Roboto+Slab:400,300,700' rel='stylesheet' type='text/css'> 
     <link href='https://fonts.googleapis.com/css?family=Roboto+Slab:400,300,700' rel='stylesheet' type='text/css'> 
     <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, target-densitydpi=device-dpi, user-scalable=0"> 
     <title>New enquiry for digifutura</title> 
    </head> 
    <body> 
    Name: vamsi gates <br> 
    Mobile: 07639817688 <br> 
    Email: [email protected] <br> 
    Requirement brief: <br> 
    hello, my name is bamsi 
    </body> 
    </html> 


    </body> 
</html> 

` ``

のしかし、私は防ぐ必要があり、接触モデル、のための場所での検証を持って取得していますこれらの種類の挿入。コンソールでは、私は、同じ情報で新しいレコードを作成することができないではないですが、レコードは、レールサーバに挿入なっている

class Contact < ApplicationRecord 
    validates :name, presence: true 
    validates :mobile, presence: true 
    validates :requirement, presence: true 
    validates :email, presence: true 
    validates_uniqueness_of :name, scope: [:mobile, :requirement, :email] 
end 

ここで連絡先のコントローラ

class ContactsController < ApplicationController 
    def create 
    @contact = Contact.new(get_params) 
    if @contact.save! 
     GuestMailer.query_email(params[:contact][:name], 
      params[:contact][:mobile], 
      params[:contact][:email], 
      params[:contact][:requirement]).deliver 
    end 
    end 

    private 

    def get_params 
    params.require(:contact).permit(:name, :mobile, :email, :requirement) 
    end 
end 

はこちらのフォームですここで

<div class="col-xs-12 col-sm-4 col-sm-offset-4"> 
    <%= simple_form_for :contact,url: contacts_path,html: {id: 'contact-form'}, authenticity_token: true, remote: true do |f| %>   
     <%= f.input :name, placeholder: 'Your Name', requried: true, label: false %> 
     <%= f.input :mobile, placeholder: 'Your Mobile Number (optional)', label: false, required: false %> 
     <%= f.input :email, placeholder: 'Your email id', required: true, label: false %> 
     <%= f.input :requirement, placeholder: 'Your Requirement in Brief', required: true, label: false, as: :text %> 
     <%= f.submit :submit, class: 'btn cta' %> 
    <% end %> 
</div> 

create.js.erb

$('.contact-form').hide(); 
$('.confirmation-message').show(); 
$(".cta").attr("disabled", true); 
0でありますの

問題:

  • 私は、2回の挿入が起こっている理由は、何がそれが2回

  • をトリガすることで、トリガが2回、検証をすべきであるにもかかわらず、第二があるかわかりません連絡先モデルで同じデータを再度保存することはできません。

+1

$( '#contact-form')。hide(); お問い合わせフォームID – Suneel

答えて

0

はこれを試してみてください、それはあなたが

<%= f.submit :submit, class: 'btn cta', data: { disable_with: "Processing" } %> 
+0

が動作していません。 – gates

0

create.jsが2回レンダリングされるために働くのだろうか? 2つのスレッドが実行されているようです。

+0

より具体的なことができますか?投稿要求が2回になっています。修理方法を教えてください。 – gates

+0

レールサーバー?? – user9392255

+0

シングルモードで起動しているプーマ... *バージョン3.6.0(ruby 2.3.1-p112)、コード名:Sleepy Sunday Serenity *最小スレッド数:5、最大スレッド数:5 *環境:開発 – gates

関連する問題