From 7d35931460e9aa9c4a719dc1d9550d768621c0e9 Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 24 Dec 2015 15:27:49 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/hjq_test.rake | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 lib/tasks/hjq_test.rake diff --git a/lib/tasks/hjq_test.rake b/lib/tasks/hjq_test.rake new file mode 100644 index 000000000..77b4bd22c --- /dev/null +++ b/lib/tasks/hjq_test.rake @@ -0,0 +1,16 @@ +namespace :hjq do + namespace :news do + desc "news order" + task :users => :environment do + a = [] + news = News.where("course_id =?", 122) + news.each do |new| + unless new.comments.blank? + new = new.comments.sort! { |a,b| a.created_on <=> b.created_on}.last.commented + end + a << new + end + puts a.length + end + end +end