2013-07-30 117 views
0

我是Rails的新手。未定義的方法`line_items_path'

這是我了LineItem控制器

class LineItemsController < ApplicationController 

def create 
    @cart=current_cart 
    product=Product.find(params[:product_id]) 
    @[email protected]_items.build(:product=>product) 
    if @line_item.save 
     redirect_to @line_item.cart 
     flash.now[:success]="Added to Cart" 
    else 
     render :action=>'new' 
    end 
end 
end 

在我的觀點一個我添加了按鈕添加到購物車

<%= button_to "Add to Cart" , line_items_path(product_id: product), class: "btn btn-primary" %> 

但是,這是給我NoMethodError

未定義方法`line_items_path'

什麼是錯誤?我哪裏錯了?

+0

發表您的routes.rb –

+0

想通了。需要添加路線。 – mrudult

回答

2

您需要將資源添加到您的路線文件:

的config/routes.rb中

resources :list_items