ruby on rails - current_cart is undefined when trying to access it from line_items controller? -


i trying make user redirect_to current_cart after click "add cart" link. doing in line items controller, , using railscasts source code reference. https://github.com/ryanb/railscasts-episodes/blob/master/episode-141/store/app/controllers/line_items_controller.rb

when click "add cart" link error:

undefined local variable or method `current_cart'

here lineitemscontroller:

class lineitemscontroller < applicationcontroller   def create   @product = product.find(params[:product_id])   @line_item = lineitem.create!(:cart => current_cart, :product => @product,     :quantity   => 1, :unit_price => @product.price)   flash[:notice] = "added #{@product.title} cart."   redirect_to current_cart_url   end end 

here cartscontroller:

class cartscontroller < applicationcontroller   def show   @cart = current_cart   end end 

thanks help.

looks line items controller missing current_cart method:

def current_cart   # should find current cart, i.e.   @current_cart ||= cart.find(session[:cart_id]) end 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -