Question

I'm newbie to Rails.

This is my LineItems Controller

class LineItemsController < ApplicationController

def create
    @cart=current_cart
    product=Product.find(params[:product_id])
    @line_item=@cart.line_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

In one of my views i added a button for Add to Cart

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

But that is giving me NoMethodError

undefined method `line_items_path'

What's the error? Where am I going wrong?

Was it helpful?

Solution

You need to add the resource to your routes file:

config/routes.rb

resources :list_items
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top