title: Display name of user all users who have liked a particular post
body: <p>I want to name(s) of all user who have liked a post.</p>
  
  <p>I have 4 models: user,post,like and review.</p>
  
  <p>A user can have many posts.
  Post can reviews &amp;&amp; post can have many likes.</p>
  
  <p>I am able to count likes on post but i am not able to display name of users who have liked a post.</p>
  
  <p><strong>Like Model:</strong></p>
  
  <pre><code>class Like &lt; ApplicationRecord
    belongs_to :post
    belongs_to :user
  end
  </code></pre>
  
  <p><strong>Post Model</strong></p>
  
  <pre><code>class Post &lt; ApplicationRecord
    belongs_to :user
    has_many :reviews, dependent: :destroy
    has_many :likes, dependent: :destroy
    validates :title, presence: true
    validates :body, presence: true
  end
  </code></pre>
  
  <p><strong>Review Model:</strong></p>
  
  <pre><code>class Review &lt; ApplicationRecord
      belongs_to :user
      belongs_to :post
  end
  </code></pre>
  
  <p><strong>User Model:</strong></p>
  
  <pre><code>class User &lt; ApplicationRecord
  
    before_create { generate_token(:auth_token) }
  
    before_save { self.email = email.downcase }
  
    has_secure_password
  
    has_many :posts
    has_many :reviews
    has_many :likes
  
    validates :name, presence: true
    validates :email, presence: true, uniqueness: true
    validates :password, confirmation: true
    validates :password_confirmation, presence: true, unless: Proc.new { |a| !a.new_record? &amp;&amp; a.password.blank? }
  
    def send_password_reset
      generate_token(:reset_password_token)
      self.reset_password_sent_at = Time.zone.now
      save!
      UserMailer.password_reset(self).deliver
    end
  
  
    def generate_token(column)
      begin
        self[column] = SecureRandom.urlsafe_base64
      end while User.exists?(column =&gt; self[column])
    end
  
  end[![enter image description here][1]][1]
  </code></pre>
  
  <p><strong>_post.html.erb</strong></p>
  
  <pre><code>&lt;h1&gt; Posts ( &lt;%= @posts.count %&gt; ) &lt;/h1&gt;
  &lt;% @posts.each do |p| %&gt;
      &lt;div class="form-field"&gt;
  
          &lt;h4&gt;
              &lt;b&gt;&lt;%= p.title %&gt;&lt;/b&gt;
              &lt;%= link_to "Edit", edit_post_path(p.id), class: "btn btn-warning col-md-2-offset", style: "align-right" %&gt; 
              &lt;%= link_to "Delete", p, method: :delete, class: "btn btn-danger col-md-2-offset" ,data: { confirm: "You sure? "}, style: "align-right" %&gt; 
              &lt;% if p.reviews.count &gt; 0 %&gt;
                   &lt;%= link_to "View Comments", review_path(p.id), class: "btn btn-primary" %&gt;
              &lt;% end %&gt;
          &lt;/h4&gt; 
          &lt;%= p.body %&gt;
          &lt;br&gt;
              &lt;% if p.likes.count &gt; 0 %&gt;
                 Likes: &lt;%= p.likes.count %&gt;
              &lt;% end %&gt;
          &lt;br&gt;
              &lt;% if Like.find_by(user_id: current_user.id,post_id: p.id) %&gt;
                 &lt;%= link_to " UnLike ", like_path(p.id), method: :delete,class: "btn btn- 
     primary fa fa-thumbs-down" %&gt;
              &lt;% else %&gt;
                 &lt;%= link_to " Like ", post_likes_path(p.id), method: :post, class: "btn btn- 
      primary fa fa-thumbs-up" %&gt;
              &lt;% end %&gt;
          &lt;br&gt; 
      &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>I was trying something like this, 
  <a href="https://i.stack.imgur.com/PRPwg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PRPwg.png" alt="enter image description here"></a></p>
  
  <p>I need to connect user,like and post table, for post which has been liked by some user. 
  I somehow need to merge two-three queries.</p>