I have the exact same problem.
same book.
same code.
same error.
So, how did you finally solve the problem ?
Thanks
Angel
--
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,
Freddy Andersen wrote:
> Where does the cart_item come from? is that in the Store controller?
> post the store controller... The view has the @cart object but also
> needs the cart_item.. Is that from the session?
cart_item.rb is the name of a model file, the one that starts with class
CartItem
Where does the cart_item come from? is that in the Store controller?
post the store controller... The view has the @cart object but also
needs the cart_item.. Is that from the session?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the
> a Sorry I see now I was thinking that the CartItem class was an
> activerecord class ... The issue is this:
> Here you call a new object of CartItem with a product passed
> @items << CartItem.new(product)
> But here in the initialize you do not have a argument for
> initialize...
> class Car
Looks like you have two open posts for the same issue... Here is the
answer from the other post...
a Sorry I see now I was thinking that the CartItem class was an
activerecord class ... The issue is this:
Here you call a new object of CartItem with a product passed
@items << CartItem.new(prod
> Probably.
>
> You could always add a parameter to your CartItem#initialize method.
> I'm
> not sure that you're heading in the direction you want to be heading,
> since
> it appears that CartItem is not derived from ActiveRecord::Base -- it's
> not
> tied to a database.
>
> You might want
>
> > CartItem#initialze
> > -- expects 0 arguments, you passed 1 argument in via CartItem#new
>
>
> I'm not really sure what do do with that -- what should I change? Are
> you saying only my CartItem#initialze is wrong?
>
Probably.
You could always add a parameter to your CartItem#initialize meth
> StoreController#add_to_cart
> -- doesn't expect any methods, but this is called by the Rails framework
> as
> an action, and Rails doesn't pass any arguments to the action methods
> Cart#add_product
> -- expects 1 argument, you're calling it with 1 argument in
> StoreController#add_to_cart
>
Your error message is:
wrong number of arguments (1 for 0)
That means that somewhere, you are calling a method that doesn't expect any
arguments and you are passing an argument to it. The stack trace give you a
clue:
ArgumentError in StoreController#add_to_cart
app/models/cart.rb:13:in `initia
Also, my add_to_cart.rhtml view looks like this:
The shopping cart
<% for item in @cart.items %>
<%= cart_item.quantity %> × <%= h(item.title) %>
<% end %>
--
Posted via http://www.ruby-forum.com/.
--~--~-~--~~~---~--~~
You received this message becaus
10 matches
Mail list logo