Line_items中的ActionView :: MissingTemplate #create

时间:2013-12-26 09:56:49

标签: ruby-on-rails

我正在发送xml请求并创建我的line_items_controller.rb的动作已执行

  def create
    @cart = current_cart
    product = Product.find(params[:product_id])
    @line_item = @cart.add_product(product.id)
    respond_to do |format|
      if @line_item.save
        format.html { redirect_to(store_url) }
        format.js { @current_item = @line_item }
        format.xml  { render :template => "/line_items/create.xml.erb", :layout => false,       
                             :status => :created, :location => @line_item }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @line_item.errors,
                             :status => :unprocessable_entity }
      end
    end
  end

我的create.xml.erb有以下代码

<?xml version="1.0" encoding="UTF-8"?>    
<script>
<![CDATA[
$("#notice").hide();

$("#cart").html("<%= escape_javascript(render(@cart)) %>");
]]>
</script>

当我运行应用程序时,我得到以下错误

**ActionView::MissingTemplate in Line_items#create**

Showing /home/ashik/work/depot/app/views/line_items/create.xml.erb where line #9 raised:

Missing partial carts/cart with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:xml], :locale=>[:en, :en]} in view paths "/home/ashik/work/depot/app/views"
Extracted source (around line #9):

6: <![CDATA[
7: $("#notice").hide();
8: 
9: $("#cart").html("<%= escape_javascript(render(@cart)) %>");
10: ]]>
11: </script>
12: 

如何在此create.xml.erb中删除该错误并成功呈现购物车部分

1 个答案:

答案 0 :(得分:0)

您需要指定“购物车”部分escape_javascript(render 'carts/cart', :cart => @cart))

的路径