错误:缺少模板推车/销毁

时间:2014-08-17 12:05:35

标签: ruby-on-rails

我收到此错误:

  

缺少模板购物车/销毁,应用/销毁{:locale => [:en],:formats => [:html],:variants => [],:handlers => [:erb ,:builder,:raw,:ruby,:jbuilder,:coffee]}。

我在cart_controller中有这段代码:

 def destroy
   @cart = Cart.find(params[:id])
   @cart.destroy
   session[:cart_id] = nil
   respond_to do |format|
     format.html { redirect_to(store_url, :notice => 'Your cart is
     currently empty') }
     format.xml { head :ok }
   end
 end
在app_controller中:

private
def current_cart
  Cart.find(session[:cart_id])
  rescue ActiveRecord::RecordNotFound
  cart = Cart.create
  session[:cart_id] = cart.id
  cart
end

在视图中:

<%= button_to 'Empty cart', @cart, :method => :delete, :confirm => 'Are you sure?' %>

我有destroy方法来执行操作但发生上述错误。问题在哪里?

1 个答案:

答案 0 :(得分:1)

before_action:set_cart,仅限:[:show,:edit,:update,:destroy]

删除销毁操作,如:

before_action:set_cart,仅限:[:show,:edit,:update]