我正在尝试让rails 4.0 (ruby2.2)中的Jquery数据表正常工作。以一种奇怪的方式。如果我转到组控制器中的Index视图(片段):
<%- model_class = Group -%>
<div class="page-header">
<h1><%=t '.title', :default => model_class.model_name.human.pluralize.titleize %></h1>
</div>
<!-- table class="table table-striped" id="groups" -->
<table class="display" id="groups">
<thead>
<tr>
<th><%= model_class.human_attribute_name(:id) %></th>
<th><%= model_class.human_attribute_name(:name) %></th>
<th><%= model_class.human_attribute_name(:address) %></th>
<th><%= model_class.human_attribute_name(:city) %></th>
<th><%= model_class.human_attribute_name(:phone) %></th>
etc..我在groups.js文件中有jquery数据表所需的javascript。
$(document).ready( function () {
$("#groups").DataTable({paging:true,
pagingType: 'full_numbers'
});
});如果我转到网址:‘`localhost:3000/group’,这是可行的。
它可以工作,我看到数据表是空的,或者数据是空的,无论数据库状态是什么,它都能工作,并且可以进行搜索。问题是如果我去创建一个新的小组..。然后保存它,它进入显示,我单击返回到goto索引,然后它显示的表,好像没有jquery-数据表在那里。标题看起来不一样,没有分页,没有搜索,什么也没有。如果我单击上面的url并按enter键,它将再次加载。
如果我没有在url框中键入组控制器,而是使用带有link_to按钮的bootstrap3按钮(来自主页索引html),这也是一样的。
<%= link_to groups_path do %>
<button type="button" class="btn btn-default btn-lg">
<span class="glyphicon glyphicon-user" aria-hidden="true" ></span> Group
</button>
<% end %>然后,它将带您到组并显示表中的所有数据,但它不是。这让我发疯了,我不知道为什么在地址栏中输入它,当一个link_to或显示表单(groups_path)上的'back‘不起作用时,它就会工作。
发布于 2015-07-08 20:02:29
得到了与您相同的问题,并通过以下步骤解决了它。
将"groups.js“文件中的第一行更改为
$(document).on "page:change", ->信息来自:rails.html#page-change-events
发布于 2016-12-16 04:51:09
您使用的是rails 4,使用turbolink添加数据的问题
<%= link_to 'Back', index_path, "data-turbolinks" => "false" %>https://stackoverflow.com/questions/29548718
复制相似问题