> ahhhh 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 CartItem
> attr_reader :product, :quantity
> def initialize
> @product = product
> @quantity = 1
> end
> Change it to this
> class CartItem
> attr_reader :product, :quantity
> def initialize( product )
> @product = product
> @quantity = 1
> end
Interesting, tried that and it's spitting a "no method for cart_item
back at me:
NameError in Store#add_to_cart
Showing app/views/store/add_to_cart.rhtml where line #4 raised:
undefined local variable or method `cart_item' for
#<#<Class:0x2602924>:0x26028e8>
Extracted source (around line #4):
1: <h1>The shopping cart</h1>
2: <ul>
3: <% for item in @cart.items %>
4: <li><%= cart_item.quantity %> × <%= h(item.title) %></li>
5: <% end %>
6: </ul>
RAILS_ROOT: script/../config/..
Application Trace | Framework Trace | Full Trace
#{RAILS_ROOT}/app/views/store/add_to_cart.rhtml:4:in
`_run_rhtml_47app47views47store47add_to_cart46rhtml'
#{RAILS_ROOT}/app/views/store/add_to_cart.rhtml:3:in `each'
#{RAILS_ROOT}/app/views/store/add_to_cart.rhtml:3:in
`_run_rhtml_47app47views47store47add_to_cart46rhtml'
Any idea?
--
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---