0

我已经制作了以 Bootstrap 3.0 提供的模式提交的表单。但是,表单仅在我刷新页面时提交,而不是在页面获得 turbolinked 时提交。在 turbolinking 上,我可以继续单击提交按钮,但没有任何反应。出于某种原因,这仅在生产中发生。

删除 turbolinks 可以解决问题,但我希望从中获得速度提升。

我认为可能的一个问题是模式最初是 display:none; 因此可能是表单未正确加载的问题。

我将在没有模式的情况下测试表单提交,但这对于我正在制作的应用程序来说是必须的。

交易控制器.rb

def create
@deal = Deal.new(deal_params)
@deal.team = @team
@deal.user_id = current_user.id

respond_to do |format|
  if @deal.save
    format.html { redirect_to team_deals_path(@team), notice: 'Deal was successfully created.' }
    format.json { render action: 'show', status: :created, location: @deal }
  else
    @deals = @team.deals.all
    iwantmodal
    should_modal_be_open
    format.html { render action: 'index' }
    format.json { render json: @deal.errors, status: :unprocessable_entity }
  end
end
end

我的表单位于索引操作本身中。

_form.html.erb

<div id="dealModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h4 class="modal-title">New Deal</h4>
  </div>
  <div class="modal-body">
    <%= simple_form_for([@deal.team, @deal]) do |f| %>
      <%= f.error_notification %>

      <div class="form-inputs">
        <%= f.input :person_id do %>
          <%= f.input_field :person_id, :collection => @team.people, class: "col-lg-10" %>
          <%= link_to content_tag(:i, nil, class: 'glyphicon-plus'), new_team_person_path, type: 'button', class: 'btn btn-success col-lg-2' %>
        <% end %>
        <%= f.input :organization_id do %>
          <%= f.input_field :organization_id, :collection => @team.organizations, class: "col-lg-10" %>
          <%= link_to content_tag(:i, nil, class: 'glyphicon-plus'), new_team_organization_path, type: 'button', class: 'btn btn-success col-lg-2' %>
        <% end %>

        <%= f.input :title %>
        <%= f.input :value %>
        <%= f.input :currency_id, :include_blank => false , :collection => Currency.all,  label_method: lambda { |obj| t("#{obj.extension}") } %>

        <%= f.input :start_date, :as => :datetime_picker, input_html: {class: "deal_start_date"} %>
        <%= f.input :close_date,:as => :datetime_picker, input_html: {class: "deal_close_date"} %>

        <%= f.input :status, collection:['Pending', 'Won','Lost'], :include_blank => false %>
        <%= f.input :phone %>
        <%= f.input :visibility_id, collection: Visibility.all,:include_blank => false %>
        <%= f.input :email %>
        <%= f.input :stage_id, :collection => @team.stages, :include_blank => false %>
      </div>
  </div>
  <div class="modal-footer">
    <div class="form-actions">
      <%= f.button :submit, class:"btn btn-primary", remote: true, method: :post %>
    </div>
  </div>
<% end %>

</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->



<script type="text/javascript">

if(<%= @modal %>) {
  $('#dealModal').modal('show')
}
</script>

该脚本仅用于在表单中出现验证错误的情况下保持模式打开。

4

2 回答 2

1

尝试将以下内容添加到您的表单中:

remote: true

然后添加:

format.js

到您的控制器操作。

这样,表单将使用一些 javascript 魔术提交。您还需要连接 js.erb 模板。

于 2014-01-02T09:40:28.150 回答
1

尝试安装这个 gem,它应该有助于对有关 turbolinks 的 jquery 问题进行排序 jquery turbolinks

于 2014-01-21T07:33:13.383 回答