Hi, I’m looking at using my table headings as links that reload the page
and sort it by the field which was clicked on. As is common, if the
list is already sorted by the field, it reverses the order. I’m now
looking at a good DRY way to do this.
I have 3 fields: name, date, race. I’m setting a parameter called so
(for sort order) to either “up” or “down” when the table header link is
clicked. Right now, my working code (in a partial) looks something like
<% if params[:v_order] == 'down' %> <%= link_to "e_date", :action =>"list_by_edate", :v_order =>
<% else %>
<%= link_to “e_date”, :action =>“list_by_edate”, :v_order =>
<% end %>
the controller has the correct code for sorting either by ‘edate’ or
Right now, I need to check which field the page is sorted by and then
use the above code for each of the three fields. I can either create 3
partials (one for each page - or just leave the above code inside the
view for the respective actions) OR look for a way to combine the 3 into
a single partial.
Any suggestions which would be better?