我正在爲學校項目構建待辦事項列表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>