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

标签 jquery datatable ruby-on-rails-4 datatables

我正在遵循 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/

相关文章:

javascript - 如何使用 jQuery Dialog OK 按钮调用函数?

php - jquery ui 可选择的复选框

javascript - 当存在多个元素时,单击一次更新值

c# - 检查DataTable中是否存在String/Record

ruby-on-rails - 哪个更好 : Constants or Models in Rails

javascript - 是否可以使用整个宽度在 A4 纸上打印 div 的内容?

javascript - 数据表行详细信息中的隐藏/显示按钮

javascript - Datatables ExcelHTMl5 导出添加页眉和页脚

ruby - 如何在 Ruby on Rails 中跟踪电子邮件?

css - form_for 添加一个带有 css 样式的 div 容器