2017-03-20 18 views
-1

提出後にフォームデータを消去する必要があります。form_tagでフォームデータをクリアするにはどうすればよいですか?

_form.html.erb

<%= form_tag(invite_user_path, method: 'post', remote: true) do |f| %> 
    <div class="form-group"> 
    <%= label_tag(:q, "Company Name:") %> 
    <%= text_field_tag(:company_name, '', class: "form-control", autofocus: true) %> 
    </div> 
    <div class="form-group"> 
    <%= label_tag(:q, "Contact Name:") %> 
    <%= text_field_tag(:contact_name, '', class: "form-control") %> 
    </div> 
    <div class="form-group"> 
    <%= label_tag(:q, "Email:") %> 
    <%= email_field_tag(:email, '', class: "form-control") %> 
    </div> 
    <div class="form-group"> 
    <%= submit_tag("Request Invitation", class: "btn btn-primary btn-sm pull-right") %> 
    <%= button_tag "Clear", type: :reset, class: "btn btn-primary btn-sm" %> 
    </div> 
    <br><br> 
<% end %> 

はコントローラー:

UserMailer.invite_users_mail(invite_users_params).deliver if validate_invite_users 
respond_to do |format| 
    format.html { redirect_to new_user_session_path, notice: 'Successfully send notification mail.' } 
    format.json { head :no_content } 
end 

後にメールを送信するとき、私は同じページにアプリケーションをリダイレクトします。だから私はフォームをクリアする必要があります。

答えて

0

フォームのパラメータからremote: trueを削除する必要があります。この方法では、フォームはAJAXを介して提出されません。

関連する問題