As far as I understand we use namely an instance variable in the method new
def new
@article = Article.new
end
because this variable is used in new.html.erb too. (Please correct me if I am wrong).
But why do we use an instance variable in the create method? Where else is it used outside the create method? Can't we just use a local variable article instead of the instance variable @article?
def create
article = Article.new(article_params)
if article.save
flash[:success] = "Article created successfully!"
redirect_to articles_url
else
render 'new'
end
end
private
def article_params
params.require(:article).permit(:title, :body)
end