Hi there,
I am doing the "depot" application from Agile Web Development With Rails book - and there is a lot of copy-and-paste. And I have to say, as a beginner in both Ruby and Rails, I don't understand quite a lot of things.
Let's talk about this thing - there is a method called "add_to_cart". I don't understand much, what it's doing... (it's in class StoreController < ApplicationController)
def add_to_cart product = Product.find(params[:id]) @cart = find_cart @cart.add_product(product) redirect_to(:action => 'display_cart') end
So, I have a few questions.
1) what exactly is product? Why it's not @product? Is it global or local variable? 2) what exactly is Product? I'm not sure, but I think its the only instance of Product class, right? Then why is the name of instance and name of the class the same? 3) What exactly is this params thing? 4) what exactly is :id? I don't understand, in which cases you use colon and in which not - why I have to use it in Product.find, but not in add_product? 5) what exactly does => mean? Why I can't use ordinary = ?
Sorry if I ask too much, I just want to understand this language and this framework.
Kaja Bilek