Hi all, I am still kind of new to the Ruby scene, and have run into a bit of a snag that I have been wrestling with all day. I have a Table that has a form that you use to filter information, and then renders the page again with the filtered information appearing in the table. Each column is able to be sorted. However, if I try to sort once a filter has been run, it defaults all the filter values to nil, and sorts the entire database of records.
this is in my Controller currently, and will work one or the other, but not both: if request.post? scope = NewRecord.scoped({}) scope = scope.conditions "file_bitrate = ?", params[:file_bitrate] unless params[:file_bitrate] == '--Select Bitrate--' scope = scope.conditions "file_quality = ?", params[:file_quality] unless params[:file_quality] == '--Select Quality--' scope = scope.conditions "file_samplerate = ?", params[:file_samplerate] unless params[:file_samplerate] == '--Select Sample Rate--' scope = scope.conditions "file_encoding = ?", params[:file_encoding] unless params[:file_encoding] == '--Select Encoding--' scope = scope.conditions "file_short = ?", params[:file_short] unless params[:file_short] == '--Select Filename--' @new_records = scope if params[:new_codec] != '--Select Codec--' @new_records.reject!{|rec| rec.pair.run.new_codec != params[:new_codec]} end end
@new_records ||= NewRecord.find(:all) if params[:sort_key] @new_records = @new_records.sort_by {|record| record.send(params[:sort_key]) } if params[:sort_reverse] @new_records = @new_records.reverse end end
If anyone has any tips on how to keep the current values of the filter, get the form to re-submit for a filter to trigger the filter, and then sort the filtered table, i would be really appreciative. Also, if anyone has a better way to do this, let me know, and I am open to change. I should note that I have no experience with js or AJAX.
Thanks so much.