我需要在提交后清除表单数据。
_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 :(得分:0)
您必须从表单的参数中删除remote: true
。这样,表单将不会通过AJAX提交。