You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
trustieforge/lib/tasks/hjq_test.rake

19 lines
574 B

namespace :hjq do
namespace :news do
desc "news order"
task :users => :environment do
a = []
# news = News.where("course_id =?", 122)
course.news.each do |new|
unless new.comments.blank?
latest_comment = new.comments.sort! { |a,b| a.created_on <=> b.created_on}.last
end
a << latest_comment
end
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