small medium large xlarge

09 Oct 2012, 17:21
Pierre Hedkvist (1 post)

Expected C:/Users/Pierre/shop/depot/app/controllers/line_items_controller.rb to define LineItemsController

I get this error when i press add to cart on one of the products. Im on page 112, any suggestions how i can fix this? thanks

This is the code in app/models/product.rb

class Product < ActiveRecord::Base

has_many :line_items

before_destroy :ensure_not_referenced_by_any_line_item

attr_accessible :description, :image_url, :price, :title

validates :title, :description, :image_url, presence: true
validates :price, numericality: {greater_than_or_equal_to: 0.01}
validates :title, uniqueness: true
validates :image_url, allow_blank: true, format: {
  with: %r{\.(gif|jpg|png)$}i,
  message: 'must be a URL for GIF, JPG or PNG image.'
def ensure_not_referenced_by_any_line_item
   if line_items.empty?
      return true
      errors.add(:base, 'Line Items present')
      return false
end end
08 Nov 2012, 23:56
Scott Carlson (1 post)

I encountered the same problem, and was able to overcome this by changing a line in the line_items_controller file to read: “@line_item = product)”, rather than “@line_item = product)”