我想顯示投票與thumbs_up寶石總投票,但它似乎並沒有工作。顯示與thumbs_up總投票計數
這裏是我的代碼
def vote_up
begin
post = Post.find(params[:id])
current_user.vote_for(post)
redirect_to :back
flash[:sucess] = "You have voted successfully"
@votes_total = post.votes_for
rescue ActiveRecord::RecordInvalid
redirect_to :back
flash[:error] = "You have already voted for this one"
end
end
在視圖: -
<%="Total votes = #{@votes_total}"%>
我得到的提示信息「您已成功投」計數,但沒有得到我的顯示票。
這是我在我的日誌文件: - 。
[1分[36米(0.3ms的)分[1mSELECT COUNT(*)FROM 「票」 WHERE 「票」 「voteable_id」 = 12, 「票」。 「voteable_type」= '郵報' 和 「票」, 「投票」= 'T'[0米0
---更新---
更新我的職位控制器與此代碼: -
def vote_up
begin
post = Post.find(params[:id])
current_user.vote_for(post)
@votes_total = post.votes_for
render :template => "home/index"
flash[:sucess] = "You have voted successfully"
rescue ActiveRecord::RecordInvalid
redirect_to :back
flash[:error] = "You have already voted for this one"
end
end
請幫忙。
即使我做了渲染,我也無法看到:template =>「home/index」 – 2012-01-11 09:03:13
請注意,您必須在'render ...'上方放置'@votes_total = post.votes_for'' – Mischa 2012-01-11 09:06:14
yes我已經完成只有那 – 2012-01-11 09:06:58