Rails: страница неактивна и неактивна после отправки модальной формы - PullRequest
0 голосов
/ 09 марта 2019

У меня есть форма внутри `начальной загрузки:

<div class="modal fade" id="form_modal" tabindex='-1'>
  <%= simple_form_for @detail_question, remote: true do |f| %>
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <h4 class="modal-title">Question</h4>
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        </div>
        <div class="modal-body">
          <%= f.error_notification %>
          <div class="form-inputs">
            <span> <span id="characterLeft"></span>.</span>
            <%= f.input :content, label: false %>

          </div>
          <div id="formModal">
            <%= render partial: 'layouts/messages' %>
          </div>
        </div>
        <div class="modal-footer">
          <%= f.button :submit, "Ask", class:" btn btn-primary" %>
        </div>
      </div>
    </div>
  <% end %>
</div>

Метод создания контроллера:

def create
  @detail_question = DetailQuestion.new(question_params)

  respond_to do |format|
    if @detail_question.save
      flash.now[:success] = "Question was successfully sent!"
      format.js { render 'create.js.erb' }
    else
      flash.now[:alert] = "Something went wrong!"
      format.js { render 'create.js.erb' }
    end
  end
end

create.js.erb

<% if @detail_question.save %>
  $("#flash").html("<%= escape_javascript(render partial: 'layouts/messages') %>");
  $("#detail_questions_<%= @detail_question.product.id %>").html("<%= escape_javascript(render partial: 'detail_questions/detail_questions', locals: { product: @detail_question.product } ) %>");
<% else %>
$("#formModal").html("<%= escape_javascript(render partial: 'layouts/messages') %>");
<% end %>

Когда я отправляю форму, модальное окно закрывается и создает вопрос, отображает флэш-сообщение, а также воспроизводит частичное, как и предполагалось. Но единственная ошибка, с которой я столкнулся ... заключается в том, что страница загружается неактивной и неактивной, пожалуйста, посмотрите на изображение ниже.

Есть идеи, что я могу делать не так?

enter image description here

1 Ответ

1 голос
/ 09 марта 2019

Короче говоря - проблема была на модальном фоне.Решается добавлением

$('#form_modal').modal('hide') 
$('.modal-backdrop').remove(); 

в create.js.rb

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...