ruby on rails - Rank posts by comments added today -
I have two models: Posts and comments I want to rank a post by # of comments posted today. So far, I have given it a place in the number of comments and I am not sure how to add today's part.
These are the post controllers:
@posts = post.order ('posts.comments_count desc') I have Have tried
@ posts = post.dr ('posts.comments_count desc'). Where ("created_at> =?", Time.son.new.bizening_off_de) but nothing returned.
Your second query will
> @posts = post. Selection (counting as 'post. *, Count (comment.id)') .Jom ((comments) where ('comments.created_at> gt; =,' time.jon.nough.bizing_off_de) .group ( 'Posts.id') .order ('count_comments desc')
If you want to include all the posts that do not have any comments today, then you have a left-hand participle will be required: @posts = post.select ('post. *, Count_comments' as count (comment id) .joins ("comments.post_id = Comments and comments on posts.id. Created_at & gt; = '# Time.zone.now.beginning_of_day}' ') .group (' posts.id ') .order (' count_comments desc ')
Comments
Post a Comment