0

Rails アプリのパーシャルにテーブルがあり、DataTables を使用して見栄えを良くしたいと考えています。jquery-datatables-rails宝石を使用しています。

私の部分:

 <script type="text/javascript">
    $(document).ready(function() {
    $('#businesses').dataTable();
    } );
    </script>

<table id="businesses">
            <thead>
                <tr>
                            Bunch of headers here...

                </tr>
                </thead>

                <tbody>
                <tr>
                Lots and lots of code here...
                </tr>
            </tbody>
        </table>

アプリケーション.js:

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require dataTables/jquery.dataTables
//= require_tree .

アプリケーション.css:

*
 * This is a manifest file that'll be compiled into application.css, which will include all the files
 * listed below.
 *
 * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
 * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
 *
 * 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 .
 */

DataTables ファイルも適切に参照されapplication.jsますapplication.css

ありがとう!

4

1 に答える 1

0

js コードを application.js ファイル内に移動する必要があります。

したがって、html.erb 内にスクリプト タグはありません。javascript の部分を実行するには、次のような application.js が必要です。

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
//= require jquery_ujs
//= require dataTables/jquery.dataTables
//= require_tree .

$('#businesses').dataTable();
    } );
于 2015-01-01T21:57:58.290 に答える