簡體   English   中英

rails redirect_to:返回不工作

[英]rails redirect_to :back not working

我正在嘗試使用以下內容:

class PaymentsController < ApplicationController

  def addproduct
     (session[:products] ||= []) << params[:item]
     redirect_to :back
  end

 end

我有這個例外:

undefined method `back_url' for #<PaymentsController:0x007ff682c467a8>

為什么會這樣?

Rails 5有redirect_back ,而不是redirect_to :back 它在用於在請求的HTTP_REFERER不存在時引發異常時被更改。

所以使用這個:

redirect_back fallback_location: root_path

您可以根據需要將root_path更改為其他內容。

redirect_to :back在Rails 5.0中被棄用(參見PR ),然后在Rails 5.1中被刪除

請改用以下內容:

redirect_back(fallback_location: root_path)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM