对于下面的代码,如果用render或vise verse替换redirect_to,会发生什么?
def create
@product = Product.new(params[:product])
respond_to do |format|
if @product.save
format.html { redirect_to(@product, :notice => 'Product was successfully created.') }
else
format.html { render :action => "new" }
end
end
end
在上面的代码中,用一个替换另一个似乎没问题.是否有一个只需要使用重定向或渲染的地方?"渲染"只会渲染视图.重定向_to向服务器发送302请求,重定向后当前参数丢失.
谢谢