Reputation: 553
I'm trying to sort questions by upvotes. The view code looks like this:
<%= Question.order(:question.upvotes.size).each do |question| %>
I keep getting this error:
undefined method `upvotes' for :question:Symbol
Here is my questions controller code:
def upvote
@question = Question.find params[:id]
@question.liked_by current_user
redirect_to comment_questions_path
end
def index
@comment = Comment.find params[:comment_id]
@questions = @comment.questions
end
Putting just
<% question.upvotes.size %>
returns the number of upvotes so that is not the problem.
Upvotes: 0
Views: 43
Reputation: 1793
This should give you the questions attached to the comment, sorted by most votes up at the top of the list.
<% @comment.questions.order("cached_votes_up desc").each do |question| %>
...
<% end %>
Upvotes: 1