Ajax不能在rails上使用ruby

时间:2014-05-29 16:45:44

标签: ruby-on-rails ruby ajax

这是catalog_controller的明确方法

def clear
@page_title = 'Vaciar Carro'
if request.xhr?
  @cart.cart_items.destroy_all
  flash[:cart_notice] = "Carro Vaciado."
  render :controller => 'cart', :action => 'clear_with_ajax'
elsif request.post?
  @cart.cart_items.destroy_all
  flash[:cart_notice] = "Carro Vaciado."
  redirect_to :controller => 'catalog'
else
  render :controller => 'cart', :action => 'clear', :template => 'cart/clear'
end
end

这是clar_with_ajax.js.erb代码

 jQuery.noConflict();
 jQuery('#shopping_cart').html("<%= j render :partial =>'cart/cart' %>");

这是调用clear方法

的视图的一部分
<p id='cart_total'><strong>Total: <%= sprintf "%0.2f €", @cart.total %></strong></p>
  <% unless @cart.cart_items.empty? %>
   <p id='clear_cart_link'>
    <b><%= link_to 'Vaciar carro', :controller => 'cart', :action => 'clear' :remote=> true %></b>
</p>
   

因为我添加了remote =&gt;在视图中,“Vaciar Carro”链接无效。

0 个答案:

没有答案