My view has this:
%tr
%th =link_to 'Name', :sort =>'name', :id => 'name_header'
My Controller method for the view has this:
@students = Student.order(params[:sort]).all
I am trying to sort by clicking on the column header.
Similarly, I tried params[:id] instead of params[:sort] but it failed too.
Make sure that the Student has the column name. This will find all the students like
find_alldoes ordered by the value that has keysortin params. We expect to be"name".And for your .haml, assign the
idfor the anchor tag;Or, assign the
idto the table header.With .merge() you keep the old parameters and, if the link is clicked, you add the GET parameter
sort. As I didn’t realize if theidis for the table header of the link I put the two solutions! As an EXAMPLE you can clone this app and see in/movies.