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
[/code]
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,
Bogdan Grosu wrote:> 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?
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---