Two ordering parameters - Rails [duplicate]

0 votes
asked Sep 11, 2017 by gustavo-rey

This question already has an answer here:

1 Answer

0 votes
answered Sep 11, 2017 by maxim-fedotov

There are a couple of ways to sort the record, but from my understanding of your question, you should be able to just update your controller action:

Edit: updated to calculate votes and use Rails 5 left_joins to include votes with count 0

def telaPrincipal
  @listOfIdeas = Idea
                   .select('ideas.*', 'COUNT( vote_count')
                   .order('vote_count DESC', created_at: :desc)
Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter