Quick beginner question about new
and create
methods. The Ruby Guide shows this example:
def new
@article = Article.new
end
def create
@article = Article.new(article_params)
if @article.save
redirect_to @article
else
render 'new'
end
end
In a different example in the guide, the statement @article = Article.new
was not used in the new
method, which makes more sense to me. The new
view doesn't need @article, the form_for
takes a parameter of the model name, then defines a variable for the form methods to use inside the |something|
. So why do we need to establish @article = Article.new
and have @article
available for the view?