SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict nueva's Avatar
    Join Date
    Apr 2006
    Location
    Uk, London
    Posts
    228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    NameError in StoreController#add_to_cart

    Ok this is the error which I am getting it from ruby on rails

    #{RAILS_ROOT}/app/controllers/store_controller.rb:8:in `add_to_cart'

    and this is the code which i have write it

    Code:
    class StoreController < ApplicationController
    def index 
      @products = Product.salable_items 
    end
    
    def add_to_cart 
    product = Product.find(params[:id]) 
    @cart = find_cart 
    @cart.add_product(product) 
    redirect_to(:action => 'display_cart') 
    end 
    
    def display_cart
      @cart = find_cart
      @items = @cart.items
    end
    end

    @cart = find_cart is the line 8

    can some one explain me here what to do?

  2. #2
    SitePoint Addict nueva's Avatar
    Join Date
    Apr 2006
    Location
    Uk, London
    Posts
    228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I have fix it in the end

    Ok I have fix it in the end, this is the code which is now working

    Code:
    class StoreController < ApplicationController
      
    def index 
      @products = Product.salable_items 
    end
    
    def add_to_cart
      product = Product.find(params[:id])
      @cart = find_cart
      @cart.add_product(product)
      redirect_to(:action => 'display_cart')
    end
    def display_cart
      @cart = find_cart
      @items = @cart.items
    end
    
    private 
    def find_cart 
      session[:cart] ||= Cart.new
    end
    end
    the add_to_cart( ) method is called as a action and it has to be add it above the private method.

    thanks for your support, even that in the end i fix it but still i am happy to be a member of this community.
    best regards dan,


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •