【发布时间】:2017-08-30 10:39:19
【问题描述】:
正在我的控制器操作中进行类似这样的重定向
format.html { redirect_to product_path(@product) }
这是带我去PUT /products/123456
但我想去GET /products/123456。
有人可以解释一下为什么会这样。我应该使用什么确切的辅助方法来处理 GET 请求?
根据文档product_path(@product) 是所有GET, PUT/PATCH 和DELETE. 的共同点
我找不到任何选项来传递类似的东西
format.html { redirect_to product_path(@product) }, method: :get
在redirect_to api 文档中。请解释我如何才能做到这一点。谢谢
更新:
def delete_product_media
@product = Product.find(params[:id])
@product_media = ProductMedium.where(id: params[:product_media_ids])
respond_to do |format|
if @product_media.update_all(deleted_at: Time.zone.now) == params[:product_media_ids].count
flash[:notice] = 'Media deleted'
flash.keep(:notice)
format.html { redirect_to product_path(@product), method: :get }
else
flash[:notice] = 'Something went wrong!'
flash.keep(:notice)
format.html {redirect_to product_path(@product) }
end
end
end
【问题讨论】:
-
你能发布更多的代码吗?
标签: ruby-on-rails ruby