Thumbs_up Gem,ajax的一个小问题

Thumbs_up Gem, a Little issue with ajax

本文关键字:一个 问题 up Gem ajax Thumbs      更新时间:2023-09-26

前几天我看到了这个链接,我决定通过ajax实现这个投票系统:JQuery+thumbs_up gem render vote count。但问题是,我几乎是一步一步地遵循它,但ajax似乎不起作用。有人能帮忙吗?非常感谢。

Micropost控制器

class MicropostsController < ApplicationController
  def vote_up
    @micropost = Micropost.find(params[:id])
    current_user.vote_exclusively_for(@micropost)
  end
  def vote_down
    @micropost = Micropost.find(params[:id])
    current_user.vote_exclusively_against(@micropost)
  end
end

votecount.html.erb

<div class='Counter'>
<span class='CounterNum'><%= @micropost.votes_for %></span>
<a href="#" class='CounterButton b2' updown="up" theid="123">
<span class='CounterIcon'></span>
</a>
<a href="#" class='CounterButton b2' updown="down" theid="123">
<span class='CounterIcon'></span>
</a>
</div>

votecount.js

$(document).ready(function(){
    $(".CounterButton").click(function() {
        var val = $(this).attr('updown');
        var theid = $(this).attr('theid');
        if (val == "up") {
            console.log('up');
        } else {
            console.log('down');
        }
    });​
});

它对我来说运行良好。。看看这个http://jsfiddle.net/GLVQe/

请确保在此jQuery代码之前添加了jQuery库文件。