【发布时间】:2014-04-02 20:48:53
【问题描述】:
我有以下代码:
= link_to "#{icon('heart')} Props".html_safe, vote_picture_path(picture), class: 'tiny radius secondary button vote', method: :put, remote: true
这里是:
# VOTE /pictures/1.json
def vote
respond_to do |format|
if @picture.toggle_vote(current_user)
format.json { render json: @picture }
else
format.json { render json: @picture }
end
end
end
我要做的是通过以下方式更新图片的总票数:
$ ->
$(".vote").on "ajax:success", (e, data, status, xhr) ->
vote_count_size = $(".vote-count .size").html()
vote_count_size_integer = parseInt(vote_count_size)
console.info data
但让我感到困惑的是 console.info 数据。它似乎从我无法分辨的来源返回了一些东西。我正在编辑 /pictures/show.json.jbuilder 但它不会影响来自数据的内容。我想返回一个带有数据总票数的 json 结构,这样我就可以从成功回调中更新页面上的计数。
【问题讨论】:
-
你能用
bind代替on吗?
标签: javascript ruby-on-rails json