crowdint / acts_as_shopping_cart

Simple Shopping Cart implementation, Official repo: https://github.com/dabit/acts_as_shopping_cart
MIT License
257 stars 88 forks source link

Uninitialized Constant Error in Controller - Rails 4.1.2 #19

Closed newterminator closed 10 years ago

newterminator commented 10 years ago

I have got the following in my controller ... following the code from the sample app. I get the error uninitialized constant ShoppingCart::ShoppingCartItem in the create method's second line.

class ShoppingCartsController < ApplicationController
  before_action :extract_shopping_cart

  def create
    @product = Product.find(params[:product_id])
    @shopping_cart.add(@product, @product.price)
    redirect_to shopping_cart_path
  end

  def show

  end

  private
  def extract_shopping_cart
    shopping_cart_id = session[:shopping_cart_id]
    @shopping_cart = session[:shopping_cart_id] ? ShoppingCart.find(shopping_cart_id) : ShoppingCart.create
    session[:shopping_cart_id] = @shopping_cart.id
  end
end
dabit commented 10 years ago

I just updated the example to use Rails 4.1.2.

Can you take a look and see if something is missing?

https://github.com/crowdint/acts_as_shopping_cart_app

newterminator commented 10 years ago

Ok @dabit I am going to check it out right now ... Thanks

newterminator commented 10 years ago

Thanks @dabit ... resolved the error ... I downloaded the updated app and went looking for the differences with mine ... And the problem was that while following the Usage instructions found here: https://github.com/crowdint/acts_as_shopping_cart#usage

Where it mentions "if you want to use convention over configuration, make sure your models are called ShoppingCart and ShoppingCartItems, then just use the shortcuts"

While generating the models I copied the names above ... so the error came when I copied "ShoppingCartItems" rather than actually looking at it and realizing that it should actually be "ShoppingCartItem"