Environment: Ruby 2.0.0, Rails 4.1, Windows 8.1, Devise, jquery-datatables-rails 1.12.2. I am also running Acts-as-tenant, which is a wonderful multi-tenant gem.
环境:Ruby 2.0.0,Rails 4.1,Windows 8.1,Devise,jquery-datatables-rails 1.12.2。我也在运行Acts-as-tenant,这是一个很棒的多租户宝石。
I have the datatables gem up and running except for one small problem. When the page is accessed from the index action, it isn't formatted and working. Only a browser refresh fires it up and then it works beautifully. Since it works after the refresh, it seems to me that the gem setup is good.
除了一个小问题,我有数据表gem并运行。从索引操作访问页面时,它没有格式化并正常工作。只有浏览器刷新才能启动它,然后它才能正常工作。由于它在刷新后起作用,在我看来宝石设置是好的。
I have attempted multiple fixes. I minimized the page so that only the table was displayed. I tried both IE and Chrome. This occurs whether or not I have cleared the browser cache and/or restarted the app. I checked the HTML to make sure I didn't see any issues there. I checked the server log to find no differences within it. Nothing I've done seems to change anything.
我尝试过多次修复。我最小化了页面,只显示了表格。我试过IE和Chrome。无论我是否已清除浏览器缓存和/或重新启动应用程序,都会发生这种情况。我检查了HTML,以确保我没有看到任何问题。我检查了服务器日志,发现其中没有差异。我所做的一切似乎都没有改变。
Here are the before and after views, showing where the page is accessed then refreshed:
以下是前后视图,显示页面的访问位置,然后刷新:
First access:
首次访问:
After refresh, all works fine:
刷新后,一切正常:
The index action is basic, but note it is scoped by Acts-as-tenant:
索引操作是基本的,但请注意它的作用范围是Acts-as-tenant:
def index
@devices = Device.all
@roles = Role.all
end
index.html.erb is:
index.html.erb是:
<div class="row">
<%= render partial: 'index', layout: 'layouts/sf_label', locals: { title: 'List Devices' } %>
</div>
The partial _index.html.erb is:
部分_index.html.erb是:
<div class="span8">
<table id="datatable">
<thead>
<tr>
<th>Device</th>
<th>Created</th>
<th>Role</th>
</tr>
</thead>
<tbody>
<% @devices.each do |device| %>
<tr>
<td><%= link_to device.name, edit_device_path(device.id) %></td>
<td><%= device.created_at.to_date %></td>
<td><%= device.roles.first.name.titleize unless device.roles.first.nil? %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
In Gemfile:
在Gemfile中:
gem 'jquery-datatables-rails', github: 'rweng/jquery-datatables-rails'
gem 'jquery-ui-rails'
In application.js:
在application.js中:
//= require dataTables/jquery.dataTables
//= require dataTables/jquery.dataTables.bootstrap
In datatable.js.coffee:
在datatable.js.coffee中:
jQuery ->
$('#datatable').dataTable()
In devices.js.coffee:
在devices.js.coffee中:
$('.datatable').dataTable({
"sPaginationType": "bootstrap"
});
In application.css.css:
在application.css.css中:
*= require dataTables/jquery.dataTables
*= require dataTables/jquery.dataTables.bootstrap
In log, which is the same either way:
在日志中,这两种方式都是相同的:
Rendered devices/_index.html.erb (253.2ms)
Rendered devices/index.html.erb within layouts/application (254.2ms)
Rendered layouts/_shim.html.erb (1.0ms)
CACHE (0.0ms) SELECT COUNT(*) FROM "roles" INNER JOIN "devices_roles" ON "roles"."id" = "devices_roles"."role_id" WHERE "devices_roles"."device_id" = $1 AND (((roles.name = 'admin') AND (roles.resource_type IS NULL) AND (roles.resource_id IS NULL))) [["device_id", 51]]
Rendered layouts/_navigation_links.html.erb (3.0ms)
Rendered layouts/_navigation.html.erb (4.0ms)
Rendered layouts/_messages.html.erb (1.0ms)
Completed 200 OK in 290ms (Views: 248.2ms | ActiveRecord: 36.0ms)
All advice appreciated...
所有建议都赞赏......
1 个解决方案
#1
10
Try this once:
尝试一次:
Add turbolinks gem into the gem file>>
将turbolinks gem添加到gem文件>>
gem 'turbolinks'
gem 'jquery-turbolinks'
And add following into application.js file.
并将以下内容添加到application.js文件中。
//= require jquery.turbolinks
//= require turbolinks
Do bundle and restart server.
捆绑并重新启动服务器。
#1
10
Try this once:
尝试一次:
Add turbolinks gem into the gem file>>
将turbolinks gem添加到gem文件>>
gem 'turbolinks'
gem 'jquery-turbolinks'
And add following into application.js file.
并将以下内容添加到application.js文件中。
//= require jquery.turbolinks
//= require turbolinks
Do bundle and restart server.
捆绑并重新启动服务器。