前几天我遇到了这个链接,我决定通过ajax实现这个投票系统:JQuery + thumbs_up gem render vote count?。但问题是我几乎一步一步地遵循它,但似乎ajax不起作用。有人可以帮忙吗?谢谢!
Micropost Controller
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');
}
});
});