我正在遵循rails强制转换#340在我的应用程序中实现数据表。
按照所有步骤,我得到了这个错误:无法找到文件'dataTables/jquery.dataTables‘
我正在使用rails 4,我发现我在教程中提到的一些文件必须创建,比如application.css和products.js.coffee
Gemfile
gem 'jquery-rails'
group :assets do
gem 'jquery-datatables-rails', github: 'rweng/jquery-datatables-rails'
gem 'jquery-ui-rails'
endApplication.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一样,我在/layout/application.html.erb中添加了对样式表的调用。
<%= stylesheet_link_tag 'application.css', media: 'all' %>和产品/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/样式表/application.css.app:6中)
有什么办法解决这个问题吗?提前感谢
发布于 2013-11-18 08:40:40
看看这个related question。我最近遇到了一个类似的问题,我的发现可能会帮你解决问题。
我看到您提到您必须创建一个application.css文件,但是您没有说明是否用任何东西填充它。您可以尝试添加:
*= require jquery.dataTables添加到application.css,并在. app /assets/datatables中包含一个jquery.dataTables.css副本,这将为您提供额外的额外好处,即能够将DataTables样式设置为与应用程序的其余部分相匹配。
进行这些更改将解决“无法找到文件”错误,因为Rails正在寻找一个CSS文件,该文件要么是:( a)不存在;要么( b)不存在于application.css文件中指定的位置。
另外,不应该将stylesheet_link_tag添加到application.html.erb文件中。资产管道的全部要点是,turbolinks将根据您在application.css中指定的内容向页面添加资产(如样式表)。
发布于 2013-11-01 05:04:29
没有别的了: Rails 4中的资产组,所以把宝石从这个块中拿出来就行了。
https://stackoverflow.com/questions/19720478
复制相似问题