Quantcast
Channel: Rails is rendering views very slowly - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Answer by Vekka for Rails is rendering views very slowly

$
0
0

I think that you need to modify this method

def popular_post        self.posts.max_by do |a|            a.likes        end    end

max_by is a method for an Enumerable class and you call it on a Post class, so this will not work properly. I would suggest that you use something like posts.order('likes DESC').first if likes is an Integer.

Also tiny hint you don't need to use all this self in an object and in class methods. Rails would assume that you call it on an object if this is an object method or you call it on a relation if this is a class method.


Viewing all articles
Browse latest Browse all 3


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>