Any one can explain me???
in agile web development book in chapter Cart Creation
depot_f/app/models/cart.rb
class Cart
attr_reader :items
def initialize
@items = []
end
def add_product(product)
@items << product
end
end
depot_f/app/views/store/index.html.erb
<%= button_to ‘Add to Cart’, :action => ‘add_to_cart’, :id => product %>
depot_f/app/controllers/store_controller.rb
def add_to_cart
product = Product.find(params[:id])
@cart = find_cart
@cart.add_product(product)
end
when use will click on Add_to_cart button in index page then width
particular product id add_to_cart action take placed in
store_controller.rb file.After finding the array of row from from
table product and assign to product variable. then find_cart method is
called in same controller which is private and create OR initialize
session. then add_product method is called width product variable then
it will goes to cart.rb model and then execute def
add_product(product)
@items << product
end
please explain me why add_product(product) method in store_controller
will go in Cart class in model cart.rb why not in other class.
thanks