How about this:
def index
@casinos = Casino.order("#{params[:sort_param]} ASC")
end
%h3 Sort by:
= link_to 'Name', casinos_path(:sort_param => "name")
%br
= link_to 'Location', casinos_path(:sort_param => "location")
The path in link_to
can take a hash which are parameters on the request. You can set a parameter (in this case sort_param
) with what value you want to sort by, then use that in your order
on the index method of the controller.