Typically, when we wish to loop with a ruby Activerecord object, we follow something like below : class CommentsController < ApplicationController def users_comments posts = Post.all comments = posts.map(&:comments).flatten @user_comments = comments.select do |comment| comment.author.username == params[:username] end end