Tips
You can start with a joins.
Answer
Post.joins(:comments).where(:comments => {user: User.first})
Tips
One includes a day keep the n + 1 query away.
Answer
Post.includes(:comments).map { |post| post.comments.size }
Tips
StackOverFlow is strong with this one.
Answer
User.where('extract(year from birthdate) < ?', 2010)
Tips
You need to write a scope, here is a tutorial.
Answer
scope :born_before, ->(year) { where('extract(year from birthdate) < ?', year) }
Tips
You need to write a validation.
Answer
validates :user, uniqueness: { scope: :post,
message: "can only comment once" }
Tips
I don't really have a hint for that because it's kind of magic.
Answer
Post.includes(:comments).where(comments: { post_id: nil })
9. We want to make sure that every time a comment is made on a post, the post timestamps are updated
Tips
You'll need a callback and, I'm not kidding, this is an hint.
Answer
You'll have a after_save callback like this in comment:
def update_post
post.touch
end