Skip to content

Instantly share code, notes, and snippets.

@alekseyl
Last active June 4, 2018 13:44
Show Gist options
  • Save alekseyl/c0ada264b47071efc7652ac18e5ced60 to your computer and use it in GitHub Desktop.
Save alekseyl/c0ada264b47071efc7652ac18e5ced60 to your computer and use it in GitHub Desktop.
class CommentsController < ApplicationController
# I assumed the usual naming for models and foreign columns
def users_comments
# I don't like where( post_id: Post.all ) but if table comments
# contains deleted posts comments or even NULLs than we need to keep it this way
@user_comments = Comment.where( post_id: Post.all )
.where(author_id: Author.where( username: params[:username]) )
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment