简体   繁体   English

Rails 4 js仅适用于页面重新加载

[英]rails 4 js only works on page reload

When I reload the page the form works but if I navigate from my app it break the remote: true form. 当我重新加载页面时,该表单有效,但是如果我从应用程序导航,则会中断remote:true表单。 All the other js on my app work fine. 我应用上的所有其他js都可以正常工作。 I got gem jquery.turbolinks.Please let me know if you need any other information. 我有宝石jquery.turbolinks。请告知我是否需要其他信息。

show.js show.js

$(".score_box<%= escape_javascript(@inspection_component.id.to_s) %>").html("Puntuación: <%= escape_javascript(@inspection_component.score.to_s) %>");
 $("#<%= escape_javascript(@inspection_component.id.to_s) %>").collapse('hide')

this my index.html.erb 这是我的index.html.erb

<div class='panel-collapse collapse' id="<%= inspection_component.id%>">
        <div class='panel-body'>
          <div class="field">
            <%= bootstrap_form_for inspection_component, remote:true, :html => {:class => 'form-inline'} do |f| %>
                <div class="form-group">
                  <%= f.select(:score, inspection_component.score_values, { :class => "form-control",label:"Puntuación" }) %>
                </div>
                <div class="form-group">
                  <%= f.submit 'Update', class: "btn btn-success" %>
                  <%= link_to 'Editar', edit_inspection_component_path(inspection_component), {:class=> "btn btn-default"} %>
                  <%= link_to 'Eliminar', inspection_component, {:class=> "btn btn-danger",method: :delete, data: { confirm: 'Are you sure?'}} %>
                </div>
            <% end %>
          </div>
        </div>
      </div>
    </div>
  <% end %>
</div>

Update Solution 更新解决方案

First of all I want to give credit to @Jeff Big, to present the solution to the problem in this post 首先我想给信贷@Jeff大,提出解决问题的在这个岗位

The solution was that I had a table with the partial for the form and the table tag was missing two very important tags th and tr 解决的办法是,我有一个表格,其中包含表格的partial,并且table标签缺少两个非常重要的标签th和tr

That's why my form tag was closing just after the first form tag. 这就是为什么我的表单标签在第一个表单标签之后关闭的原因。 Like this: 像这样:

<form accept-charset="UTF-8" action="/inspection_components/4" class="edit_inspection_component" data-remote="true" id="edit_inspection_component_4" method="post"><div style="display:none"><input name="utf8" type="hidden" value="✓"></form>

First of all I want to give credit to @Jeff Big, to present the solution to the problem in this post 首先我想给信贷@Jeff大,提出解决问题的在这个岗位

The solution was that I had a table with the partial for the form and the table tag was missing two very important tags th and tr 解决的办法是,我有一个表格,其中包含表格的partial,并且table标签缺少两个非常重要的标签th和tr

That's why my form tag was closing just after the first form tag. 这就是为什么我的表单标签在第一个表单标签之后关闭的原因。 Like this: 像这样:

<form accept-charset="UTF-8" action="/inspection_components/4" class="edit_inspection_component" data-remote="true" id="edit_inspection_component_4" method="post"><div style="display:none"><input name="utf8" type="hidden" value="✓"></form>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM