rweng / jquery-datatables-rails

jquery-datatables gem for rails
MIT License
564 stars 338 forks source link

DataTables not loading in Rails 4.0.8 app with Bootstrap 3 #133

Closed bnzelener closed 10 years ago

bnzelener commented 10 years ago

Hey guys, my Rails app REFUSES to load DataTables. I am using Rails 4.0.8 and the Bootstrap-Sass 3.2.0 gem. My table appears just fine, but zero of the DataTables features show up. Here's a screenshot:

screenshot 2014-10-29 19 29 05

application.js

//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
//= require bootstrap-sprockets
//= require bootstrap-datepicker
//= require dataTables/jquery.dataTables
//= require dataTables/bootstrap/3/jquery.dataTables.bootstrap

application.css

 *= require_self
 *= require_tree .
 *= require bootstrap-datepicker3
 *= require dataTables/bootstrap/3/jquery.dataTables.bootstrap
 */

Gemfile

source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=railstutorial_rails_4_0

gem 'rails', '4.0.8'
gem 'bootstrap-sass', '3.2.0'
gem 'autoprefixer-rails'
gem 'sass-rails', '~> 4.0.0'
gem 'sprockets', '2.11.0'
gem 'bcrypt-ruby', '3.1.2'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'
gem 'nokogiri', '1.6.3.1'
gem 'rest-client', '1.7.2'
gem 'bootstrap-datepicker-rails', '1.3.0.2'
gem 'easypost', '2.0.12'
gem 'savon', '2.7.2'
gem 'figaro'
gem 'jquery-datatables-rails', '~> 3.0.0'

group :development, :test do
  gem 'sqlite3', '1.3.8'
  gem 'rspec-rails', '2.13.1'
  gem 'guard-rspec', '2.5.0'
  gem 'spork-rails', '4.0.0'
  gem 'guard-spork', '1.5.0'
  gem 'childprocess', '0.3.6'
end

group :test do
  gem 'selenium-webdriver', '2.35.1'
  gem 'capybara', '2.1.0'
  gem 'growl', '1.0.3'
  gem 'factory_girl_rails', '4.2.0'
end

group :doc do
  gem 'sdoc', '0.3.20', require: false
end

group :production do
  gem 'pg', '0.15.1'
  gem 'rails_12factor', '0.0.2'
end

Table Code

<script>
    $('#datatable').DataTable();
</script>

<table id="datatable" class="table">
    <thead>
        <tr>
            <th>Name</th>
            <th>Email</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Kevin Mitnick</td>
            <td>kevin@pacificbell.com</td>
        </tr>
        <tr>
            <td>Martin Bishop</td>
            <td>marty@toomanysecrets.com</td>
        </tr>
        <tr>
            <td>Neo</td>
            <td>mranderson@thereisnospoon.com</td>
        </tr>
    </tbody>
</table>

Any thoughts?

bnzelener commented 10 years ago

SOLVED!

The problem was I had coffee script syntax in <script> tags in my HTML file. When I put them in the appropriate js.coffee file in the javascript folder, the Rails Asset Pipeline seems to have found them.