0
我寫了一個動作,它再次調用另一個私有方法,如果滿足特定條件,我想重定向到其他頁面或繼續執行。 但我無法做到, 當我試圖使用redirect_to root_path
它說雙渲染, 它實際上是試圖執行實際調用的行動聲明,而不是從私有方法渲染。如何在redirect_to被調用後停止執行
def actual_method_called
data1 = params[:data1]
method_2(data1)
data2 = params[:data1]
method_2(data2)
render json: {status: 'ok' }
end
private
def method_2(data)
if data.valid?
puts 'continue the execution'
else
redirect_to root_path and return
end
end
您使用on Rails的Ruby的是什麼版本? –
Rails 5.0.0.1版本 ruby 2.2.5p319 – chinna2580
您可以將'method_2'放入'before_action'過濾器中。 –