首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >找不到文件'dataTables/jquery.dataTables‘Rails 4

找不到文件'dataTables/jquery.dataTables‘Rails 4
EN

Stack Overflow用户
提问于 2013-11-01 03:48:28
回答 2查看 5.5K关注 0票数 4

我正在遵循rails强制转换#340在我的应用程序中实现数据表。

按照所有步骤,我得到了这个错误:无法找到文件'dataTables/jquery.dataTables‘

我正在使用rails 4,我发现我在教程中提到的一些文件必须创建,比如application.css和products.js.coffee

Gemfile

代码语言:javascript
复制
gem 'jquery-rails'
group :assets do 
  gem 'jquery-datatables-rails', github: 'rweng/jquery-datatables-rails'
  gem 'jquery-ui-rails'
end

Application.js

代码语言:javascript
复制
//= require jquery
//= require dataTables/jquery.dataTables
//= require_tree .

Application.js.coffee

代码语言:javascript
复制
 /* 
 * 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中添加了对样式表的调用。

代码语言:javascript
复制
<%= stylesheet_link_tag 'application.css', media: 'all' %>

和产品/index.htm.erb

代码语言:javascript
复制
<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中)

有什么办法解决这个问题吗?提前感谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-11-18 08:40:40

看看这个related question。我最近遇到了一个类似的问题,我的发现可能会帮你解决问题。

我看到您提到您必须创建一个application.css文件,但是您没有说明是否用任何东西填充它。您可以尝试添加:

代码语言:javascript
复制
*= 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中指定的内容向页面添加资产(如样式表)。

票数 2
EN

Stack Overflow用户

发布于 2013-11-01 05:04:29

没有别的了: Rails 4中的资产组,所以把宝石从这个块中拿出来就行了。

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19720478

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档