gpt4 book ai didi

redirect - 如何在 Rails 3 中的 redirect_to 调用中允许自定义闪存键

转载 作者:行者123 更新时间:2023-12-03 15:15:32 26 4
gpt4 key购买 nike

在 Rails 3 中,您可以将 has 属性直接传递给 redirect_to设置闪光灯。例如:

redirect_to root_path, :notice => "Something was successful!"

但是,这只适用于 :alert:notice key ;如果要使用自定义键,则必须使用更详细的版本:
redirect_to root_path, :flash => { :error => "Something was successful!" }

有什么方法可以使自定义键(例如 :error ,上面)可以传递给 redirect_to没有在 :flash => {} 中指定它?

最佳答案

在 Rails 4 中你可以这样做

class ApplicationController < ActionController::Base
add_flash_types :error, ...

然后在某个地方
redirect_to root_path, error: 'Some error'

http://blog.remarkablelabs.com/2012/12/register-your-own-flash-types-rails-4-countdown-to-2013

关于redirect - 如何在 Rails 3 中的 redirect_to 调用中允许自定义闪存键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3848755/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com