2012-07-12 1 views
0

필자는 레일 앱의 일부분에 테이블을 가지고 있으며, DataTables를 사용하여 멋지게 보이고 싶습니다. jquery-datatables-rails 보석을 사용하고 있습니다.내 레일에서 DataTable이 부분적으로 작동하지 않는 이유는 무엇입니까?

내 부분 :

<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> 

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 . 

application.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.jsapplication.css 제대로 참조됩니다.

감사합니다.

+0

은 당신이 의 내부에만 사용하고 있는지 확인. 자바 스크립트 콘솔 (크롬의 f12)에서 오류를 찾으십시오. – Pheonix

+0

명시된대로 만 사용하고 있습니다. 디버깅 팁을 주셔서 감사합니다. 오류는'$ ("# businesses")입니다. dataTable은 함수가 아닙니다. "... – Slicekick

+0

브라우저는이 페이지에서 datatable.js 파일을 찾을 수 없습니다. 관련 코드 application.js를 여기에 추가하십시오. – Pheonix

답변

0

js 코드를 application.js 파일로 옮겨야합니다.

그래서, 당신의 html.erb 내부에 스크립트 태그는, 당신이 그와 같은 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(); 
    }); 
관련 문제