賛成票で質問を並べ替えようとしています。ビューのコードは次のようになります。
<%= Question.order(:question.upvotes.size).each do |question| %>
このエラーが発生し続けます:
undefined method `upvotes' for :question:Symbol
これが私の質問のコントローラーコードです:
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
ちょうど置く
<% question.upvotes.size %>
賛成票の数を返すので、それは問題ではありません。