我正在为学校项目构建待办事项列表Web应用程序,并且试图让列的标题可点击,并且当您单击他们,他们整理信息。我已经在这里和谷歌教程尝试过很多解决方案,也许有人可以直接帮助我?如何在Ruby on Rails应用程序中对表的列进行排序
这里就是我想:
projects_controller.rb
def index
@projects = Project.all
@products = Project.order(params[:sort])
end
projects.js
$(document).ready(function(){
$('/index.html.erb').DataTable();
});
index.html.erb
<thead>
<tr id="headers">
<th><%= link_to "Title", :sort => "title" %></th>
<th><%= link_to "Client", :sort => "client" %></th>
<th>Description</th>
<th>Hours</th>
<th><%= link_to "Done", :sort => "done" %></th>
<th colspan="3"></th>
</tr>
</thead>