jQuery + thumbs_up gem渲染投票计数?
|
外挂程式:
Thumbs Up&JQuery 1.5.2(需要另一个旧的gem)
当用户对帖子投票时,我正在尝试提供不带完整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>
表决_up.erb.js(在岗位文件夹)。
$(\".votecount\").html(
\"<%= escape_javascript post.votes_for - post.votes_against %>\");
我已经坚持了一段时间,非常感谢您能提供的任何帮助。我已经看过Jquery的Railscast并浏览了其他Stackoverflow的答案,但是我对Jquery仍然不太满意。
没有找到相关结果
已邀请:
1 个回复
襄挟款籍
做类似的事情:
在您的视图中,将votwrapper div移出到同一目录中名为\“ _ votecount.html.erb \”的新文件中,而是使用呈现代码:
如果您想在刷新时阻止评级(推荐),那么您可能希望取消调用并在js中对其进行更多控制。因此,在视图中包含您的JavaScript:
用优质的html替换您的link_to以获取更多信息:
并在public / javascripts文件夹中创建一个新的votecount.js,其中包含以下内容:
祝好运! :)