[英]Maintain params from previous page with respond_to
我有一个属于产品的模型产品属于一个模型商店(有许多产品)。
当我为商店创建新产品时,我使用的是以下网址:
/products/new?store_id=4
当产品创建通过验证失败时,我将被重定向到:
/products
这是此“创建”操作的response_to:
respond_to do |format|
if @product.save
format.html { redirect_to(@product.store, :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
理想情况下,我想将创建失败的用户重定向回以前的确切网址,即:
/products/new?store_id=4
谢谢,
哈里斯
也许有帮助吗?
@store_id = params[:store_id]
respond_to do |format|
if @product.save
format.html { redirect_to(@product.store, :notice => 'Product was successfully created.') }
format.xml { render :xml => @product, :status => :created, :location => @product }
else
format.html { render :action => "new", :store_id => @store_id }
format.xml { render :xml => @product.errors, :status => :unprocessable_entity }
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.