Javascript Rails中带有表排序器的“未定义不是函数”
我正在尝试在Rails视图上使用Tablesorter。视图的haml为:Javascript Rails中带有表排序器的“未定义不是函数”,javascript,jquery,ruby-on-rails-4,tablesorter,Javascript,Jquery,Ruby On Rails 4,Tablesorter,我正在尝试在Rails视图上使用Tablesorter。视图的haml为: - @page_title = 'Users' :javascript $(document).ready(function() { $("#data_table").tablesorter(); } ); %table#data_table %thead %tr %th Username %th Email %th Ro
- @page_title = 'Users'
:javascript
$(document).ready(function()
{
$("#data_table").tablesorter();
}
);
%table#data_table
%thead
%tr
%th Username
%th Email
%th Role
%th Internal
%th
%tbody
- @users.each do |user|
%tr{:class => cycle('list_line_odd', 'list_line_even')}
%td= user.username
%td= user.email
%td= user.role_name
%td= user.internal
%td{:class => 'list_actions'}
= link_to 'Show', user
%br/
= link_to 'Edit', edit_user_path(user)
%br/
= link_to 'Destroy', user, method: :delete, data: { confirm: 'Are you sure?' }
%br/
My application.js具有:
当我加载页面时,JavaScript控制台显示一个错误UncaughtTypeError:undefined不是$data\u table.tablesorter;行上的函数;。其他报告类似问题的人说,这可能是因为jQuery加载了两次,但我不知道如何判断是否发生了这种情况,或者在Rails结构中如何处理它我还不知道JavaScript或jQuery
我该如何着手解决这个问题
编辑:我应该提到jquery和jquery.tablesorter JavaScript文件位于app/assets/javascripts中。要查看是否包含jquery两次,只需查看生成的页面的源代码,并查看是否包含多个jquery。此外,您还可以检查在jquery之后添加了tablesorter插件脚本。啊,当你知道自己在做什么时,这是显而易见的是的,它加载了两个副本,一个是我放在app/assets/javascripts中的,另一个是来自我不知道消息来源是assets/jquery.js'的,但它似乎不在我的任何资产目录中。
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require jquery.tablesorter
//= require_tree .