【发布时间】:2011-03-10 01:20:43
【问题描述】:
一个脚手架像这样生成新的动作:
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 操作也实例化了一个新对象。是否仅用于将表单绑定到对象,以便一切从一个动作到另一个动作正确进行?
【问题讨论】:
标签: ruby-on-rails ruby scaffolding controllers