Topic: div_for, form_for parameters

I'm reading the book Beginning Rails 3. The app being built has users posting Articles and other users posting Comments to the Articles. An Article has_many Comments and a Comment belongs_to Article.

Now in the Article and Comment partials the beginning code looks like this:

<%= div_for article do %>

<%= div_for comment do %>

I don't understand these two lines. First of all what does div_for do exactly? And secondly where do the variables 'article' and 'comment' come from?

My other question is regarding app/views/comments/new.html.erb. The code looks like this:

<%= form_for([@article,]) do |f| %>

Can someone explain why these two variables are in there and what they do?

Re: div_for, form_for parameters

Question one:
div_for is erb code for output a <div>, article collects the article information passed to it from the controller, who got it from your article model (the do part is a ruby way of creating a block of code to be executed, in this example, printing all the article information), and comment is passing an array of comment objects that will be iterated over.

Question two:
form_for creates a html <form> tag, filling in all of the needed information like the method, path, etc. It also will give you access to the model architecture so the name in the model easily matched the form name, etc. The reason you need both the @article and is the relationship between article (has_many) and comments(belongs_to). The @article variable tells the form which article the comments belongs to, and the creates the comment obj. that the form is actually creating.