Rails 重定向到另一个控制器的显示方法
Rails redirect to another controller's show method
在 currency
的控制器中,我想重定向到 prediction
的显示方法。我该怎么做?
def update
respond_to do |format|
if @currency.update(currency_params)
prediction = @currency.neural_network.predict
###redirect to prediction's controller, show method
###???
else
format.html { render :edit }
format.json { render json: @currency.errors, status: :unprocessable_entity }
end
end
end
只需添加redirect_to prediction
对特定对象执行 redirect_to 会转到该对象的显示页面。 Rails 知道 prediction
是一个活动记录对象,因此它会将其解释为知道您想转到该对象的显示页面。
redirect_to(options = {}, response_status = {}) public
Redirects the browser to the target specified in options.
你可以做到 redirect_to prediction
Rails 将自动解析模型的路径。
在 currency
的控制器中,我想重定向到 prediction
的显示方法。我该怎么做?
def update
respond_to do |format|
if @currency.update(currency_params)
prediction = @currency.neural_network.predict
###redirect to prediction's controller, show method
###???
else
format.html { render :edit }
format.json { render json: @currency.errors, status: :unprocessable_entity }
end
end
end
只需添加redirect_to prediction
对特定对象执行 redirect_to 会转到该对象的显示页面。 Rails 知道 prediction
是一个活动记录对象,因此它会将其解释为知道您想转到该对象的显示页面。
redirect_to(options = {}, response_status = {}) public
Redirects the browser to the target specified in options.
你可以做到 redirect_to prediction
Rails 将自动解析模型的路径。