插件: Thumbs Up &的JQuery 1.5.2(需要另一位寶石)JQuery + thumbs_up gem render vote count?
我試圖呈現一個更新的計票結果W/O完整的HTTP請求時,一則訊息的用戶投票。目前,它在每次投票中刷新頁面。
帖子控制器
def vote_up
post = Post.find(params[:id])
current_user.vote_exclusively_for(post)
respond_to do |format|
format.js
format.html {rRedirect_to :back}
end
end
def vote_down
post = Post.find(params[:id])
current_user.vote_exclusively_against(post)
respond_to do |format|
format.js
format.html {redirect_to :back}
end
end
查看投票(每個崗位div有左邊一票DIV(Digg的/ reddit的風格)和內容右側)
<div class="post">
<div class="vote">
<div class="votewrapper">
<span class="votecount">
<%= post.votes_for - post.votes_against %>
</span>
<div class="votebtn">
<%= link_to image_tag('vote.png'), vote_up_post_path(post), :method => :post, :format => :js %>
</div>
</div>
</div>
<div class="postcontent">
all the post content, timestamp stuff, etc...
</div>
</div>
vote_up.erb.js (在Posts文件夾中)。
$(".votecount").html(
"<%= escape_javascript post.votes_for - post.votes_against %>");
我一直堅持這一段時間,非常感謝任何幫助你們可以提供。我已經看過JQuery的railscast,並通過其他Stackoverflow的答案,但我仍然在Jquery很不喜歡。
真棒現在我有我的網站上的JavaScript,謝謝兄弟! – ahuang7 2011-06-21 04:58:13
是'$ .block()'一個插件?我似乎沒有可用的方法。 – 2012-11-13 06:29:18