Monday, April 27, 2009

Sort with Array of Hashes

@list = @list.sort_by {|s| s[params[:order]].downcase} #case-insensitive
@list.reverse! if params[:direction] == "DESC"


Nil Case
@list = @list.sort_by {|s| (s[params[:order]].nil? ? 100.years.ago : s[params[:order]])} #datetime case

No comments: