나는 upvotes로 질문을 정렬하려고합니다. 뷰 코드는 다음과 같습니다 내 질문 컨트롤러 코드 여기포스트 오더 오류
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 %>
퍼팅 나는이 오류가 계속
<%= Question.order(:question.upvotes.size).each do |question| %>
upvote의 수를 반환합니다. 그래서 문제가되지 않습니다.
이전 답변에서 설명한대로 캐시 된 열을 사용해야합니다. 'Question.order (: cached_votes_up)를 시도해보십시오. 각 작업 | q | ... '. –
답변을 주셔서 감사합니다. (다시). 마이그레이션을 통해 질문에 cached_votes_up, : integer, : default => 0을 추가 할 수 없습니다. 어떻게 내가 이걸 할 수 있을까? – user2759575
앱을 볼 필요가 있습니다. 그것을 github에 게시 할 수 있습니까? –