在Michael Hartl的教程之后,我开始更多地研究rails并决定将我已经构建的内容与以下简单的购物车教程http://www.sitepoint.com/build-online-store-rails/
结合起来一切正常,直到最后,我试图从购物车中删除现有商品,并期望数量计数相应地改变。我对javascipt一般都比较新,所以任何提示都会非常感激。
推车/ show.html.erb
<div id="mycart" class="small-10 small-centered medium-8 large-8 column">
<div class="p1 glassy-bg mb1 text-center radius-l1 radius-r1">
<h4>My Cart</h4>
<p class="mb0"> You've selected <span class="cart-count"><%=current_user.cart_count%></span> movies!</p>
</div>
<% @cart_panels.each do |panel|%>
<div data-equalizer class="cart-movie large-12 column mb1">
<div class="column large-7 glassy-bg text-center" data-equalizer-watch>
<p class="scale ptm"> <%= panel.title %> </p>
</div>
<div class="column large-3 primary-bg text-center radius-r1" data-equalizer-watch>
<%=link_to "" , data: {targetUrl: remove_from_cart_path(panel)} do%>
<i class="fi-x right"></i> REMOVE
<%end%>
<h4 class="scale">$ <%= panel.price %></h4>
</div>
</div>
<%end%>
</div>
carts.js.coffee
$(window).load ->
$('#mycart .fi-x').click (e) ->
e.preventDefault()
$this = $(this).closest('a')
url = $this.data('targeturl')
$.ajax url: url, type: 'put', success: (data) ->
$('.cart-count').html(data)
$this.closest('.cart-movie').slideUp()
上面几乎是教程中代码的完全复制品,但我的工作不正常。我在这里做错了什么?