I'm going through a tutorial here and running into an error I'm not sure
how to fix..this is my first foire into sessions.

Trying to create a shopping cart for a store app. I'm getting this
error:

wrong number of arguments (1 for 0)

RAILS_ROOT: script/../config/..

Here is my cart_item.rb model:

class CartItem
  attr_reader :product, :quantity

  def initialize
    @product = product
    @quantity = 1
  end

  def increment_quantity
    @quantity += 1
  end

  def title
    @product.title
  end

  def price
    @product.price * @quantity
  end
end

And my cart.rb model:

class Cart
  attr_reader :items

  def initialize
    @items = []
  end

  def add_product(product)
    current_item = @items.find {|item| item.product == product}
    if current_item
      current_item.increment_quantity
    else
      @items << CartItem.new(product)
    end
  end
end

And my add_to_cart.rhtml view:

<h1>The shopping cart</h1>
<ul>
  <% for item in @cart.items %>
    <li><%= cart_item.quantity %> &times; <%= h(item.title) %></li>
  <% end %>
</ul>

When I first tried clicking the add to cart function for a product I got
an error that method 'product' was undefined but then I did rake
db:sessions:clear and now I am getting this wrong number of arguments
error - any ideas?

Thanks!
-- 
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@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to