scaffold は、次のような新しいアクションを生成します。
def new
@product = Product.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @product }
end
end
def create
@product = Product.new(params[:product])
respond_to do |format|
if @product.save
format.html { redirect_to(@product, :notice => 'Product was successfully created.') }
format.xml { render :xml => @product, :status => :created, :location => @product }
else
format.html { render :action => "new" }
format.xml { render :xml => @product.errors, :status => :unprocessable_entity }
end
end
end
ビューは という名前のパーシャルをレンダリングしform
ます。new
フォームは新しい製品を作成するように設定されたアクションでレンダリングされるため、 の目的は何@product
ですか? create
アクションによって新しいオブジェクトもインスタンス化されていることがわかります。フォームをオブジェクトに結び付けて、すべてがアクションからアクションへと正しく進むようにするためだけに使用されますか?