我正在遵循 Railscast #340 在我的应用程序中实现数据表。
按照所有步骤,我收到此错误: 找不到文件“dataTables/jquery.dataTables”
我正在使用 Rails 4,我发现教程中提到的一些文件我必须创建,例如 application.css 和 products.js.coffee
gem 文件
gem 'jquery-rails'
group :assets do
gem 'jquery-datatables-rails', github: 'rweng/jquery-datatables-rails'
gem 'jquery-ui-rails'
end
应用程序.js
//= require jquery
//= require dataTables/jquery.dataTables
//= require_tree .
Application.js.coffee
/*
* This is a manifest file that'll automatically include all the stylesheets available in this directory
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
* the top of the compiled file, but it's generally better to create a new file per style scope.
*= require_self
*= require dataTables/jquery.dataTables
*= require_tree .
*/
与 Rails 4 一样,我在/layouts/application.html.erb 中添加了对样式表的调用
<%= stylesheet_link_tag 'application.css', media: 'all' %>
和 products/index.htm.erb
<table class="table table-normal" id="products" >
<thead>
<tr>
<td>Code</td>
<td>Name</td>
<td>Description</td>
<td>Price</td>
<td>Stock</td>
<td>Enabled</td>
<td>Company</td>
</tr>
</thead>
<tbody>
<% @products.each do |product| %>
<tr>
<td style="text-decoration: underline;"><%= link_to product.code, edit_product_path(product) %></td>
<td><%= product.name %></td>
<td><%= product.description %></td>
<td><%= product.price %></td>
<td><%= product.stock %></td>
<td><%= product.enabled %></td>
<td><%= product.company_id %></td>
</tr>
<% end %>
</tbody>
</table>
我在输出中收到此错误
找不到文件“dataTables/jquery.dataTables” (在....app/assets/stylesheets/application.css:6中)
有什么想法可以解决这个问题吗? 提前致谢
最佳答案
Rails 4 中不再有 :assets 组,因此只需将 gem 从该 block 中取出即可。
关于jquery - 找不到文件 'dataTables/jquery.dataTables' Rails 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19720478/