我是新来的铁轨,并且对以下代码中的format.json
行感到困惑。 status: :created
和location: @product
指的是什么?这些参数在respond_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.' }
format.json { render json: @product, status: :created, location: @product }
format.js
else
format.html { render action: "new" }
format.json { render json: @product.errors, status: :unprocessable_entity }
format.js
end
end
end
是否包括状态和位置可选?我主要对什么是可选的以及为什么可以添加自定义状态/位置感到困惑。
的[什么\'可能重复:位置=> ... \'和\'头:OK \'指的是在“回应\ _to'format statement?](http://stackoverflow.com/questions/5213956/what-does-location-and-head-ok-mean-in-the-respond-to-format-stat) –