The problem is that the unary -
operator in not defined in the class Time used by created_date
. You should convert it to an integer :
items.sort_by{|x| sort_direction == :asc ? x.created_date.to_i : -x.created_date.to_i}
That could also be written
items.sort_by{|x| x.created_date.to_i * (sort_direction == :asc ? 1 : -1)}