我已经加载了 Thumbs_Up gem,并且投票工作正常。
我将此代码添加到帖子控制器:
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