0

나는 Thumbs_Up 보석을로드했으며 투표가 정상적으로 작동합니다. Ruby On Rails : 엄지 손가락 투표 투표 집계 결과

나는 게시물 컨트롤러에이 코드를 추가 :

def poll_winners 
@posts = Post.tally(
{ :at_least => 1,  
    :limit => 20, 
    :order => 'vote_count desc' 
}) 

난 그냥 표시 할 얻기 위해 실제보기에 넣어 무엇을 알아낼 수 없습니다.

그냥 <% poll_winners %>입니까?

EDIT2 : (이 맞다면 확실하지)

undefined local variable or method `poll_winners' for #<#<Class:0x000000040a4278>:0x007f55806c3360> 

* 편집 * 여기 내 전체 게시물 컨트롤러 :

class PostsController < InheritedResources::Base 
def vote_up 
begin 
    current_user.vote_for(@post = Post.find(params[:id])) 
    redirect_to [@post] 
    flash[:success] = "You have voted successfully" 
rescue ActiveRecord::RecordInvalid 
    redirect_to [@post] 
    flash[:error] = "You have already voted" 
end 
end 
def poll_winners 
    @posts = Post.tally(
{ :at_least => 1, 
    :at_most => 10000, 
    :limit => 10, 
    :order => 'vote_count desc' 
}) 
end 
end 

답변

1

을 통해 당신이 할 수있는 단지 루프 여기에 전체 오류 메시지입니다 방법의 결과 poll_winners

그런 다음 Post의 특정 속성을 가져올 수 있습니다. 예를 들어 title이있는 경우 <%= pw %> 대신 <%= pw.title %>을 수행하면 해당 객체를 반환 할 수 있습니다.

나는 지금이 글 컨트롤러 권리를 "정의되지 않은 지역 변수 poll_winners"를한다 얻고있다

def poll_winners 
    @posts = Post.tally(
    :at_least => 1,  
    :limit => 20, 
    :order => 'vote_count desc' 
    }) 
end 
+0

을 다음과 같은 방법이 있다고 가정입니까? 클래스가 PostsController 1, : at_most => 10000, : 제한 => 10, : 주문 => 'vote_count desc' }) end end –

+0

메시지 : 정의되지 않은 지역 변수 또는 # <# <클래스 : 0x000000040a4278> : 0x007f55806c3360> –

+0

의'poll_winners '메소드'poll_winners' 메소드를 컨트롤러에서 헬퍼로 이동하십시오. 헬퍼 폴더에는'post_helper.rb'라는 파일이 있어야합니다. –