没有答案对我有用…这就是我最终要做的事情:
事物/show.hmtl.erb:
<div id="<%= thing.name %>"> <%= thing.up_votes.count %> </div><a id="<%= thing.name.downcase %>_link"><%= link_to "upvote", upvote_thing_path(:id => thing.id), remote: true, method: :get %></a><script type="text/javascript"> $("#<%= thing.name.downcase %>_link").click(function () { $.get( "<%= upvote_thing_path(:id => thing.id) %>", function( data ) { $('#<%= thing.name %>').html(data + ' %'); }); });</script>
控制器/things_controller.rb
def upvote @thing = Thing.find(params[:id]) UpVote.create!(ip: request.remote_ip, vanishing: false, voteable_id: params[:id], voteable_type: 'Thing') redirect_to @thing render text: @thing.up_votes.count.to_send
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)