This commit is contained in:
huang 2015-12-25 10:06:48 +08:00
parent a92d33300b
commit ad46564545
1 changed files with 7 additions and 5 deletions

View File

@ -3,14 +3,16 @@ namespace :hjq do
desc "news order"
task :users => :environment do
a = []
news = News.where("course_id =?", 122)
news.each do |new|
# news = News.where("course_id =?", 122)
course.news.each do |new|
unless new.comments.blank?
new = new.comments.sort! { |a,b| a.created_on <=> b.created_on}.last.commented
latest_comment = new.comments.sort! { |a,b| a.created_on <=> b.created_on}.last
end
a << new
a << latest_comment
end
puts a.length
comments = a.map(&:commented_id).detect{|a.b| a.created_on <=> b.created_on}
# comments = a.sort!{|a.b| a.created_on <=> b.created_on}
news = News.where("id in (?)", comments)
end
end
end