Я создал формы для отправки в модальных окнах, предоставляемых Bootstrap 3.0. Однако формы отправляются только тогда, когда я обновляю страницу, а не когда страницы получают турбоссылку. При турболинковке я могу продолжать нажимать кнопку отправки, и ничего не происходит. Это происходит только в производстве по какой-то причине.
Удаление турболинков решает проблему, но я хочу получить от этого прирост скорости.
Я думаю, что одна проблема может заключаться в том, что модальные окна изначально отображаются: нет; поэтому может быть проблема в том, что формы не загружаются должным образом.
Я протестирую отправку форм без модальных окон, но это необходимо для приложения, которое я делаю.
deals_controller.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
У меня есть форма, расположенная в самом действии index.
_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">×</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>
Сценарий просто используется для того, чтобы держать модальное окно открытым на случай, если в форме есть ошибки проверки.