Better way of checking if the current user already like a post
Have you created an index for likes.post_id? Note also that you can simplify that method by using has_many with the option through and  ActiveRecord#include?. That's what I'd write (with positive logic, I don't see why has_like_from? should perform a == nil):

class Post &lt; ActiveRecord::Base
  belongs_to :user, :counter_cache =&gt; :count_post
  has_many :likes
  has_many :like_users, :through =&gt; :likes

  def liked_by?(user)
    like_users.include?(user)
  end
end