我在GitHub上分叉了一个项目,有一些flash消息。例如,在我分叉的项目中使用Twitter签名时,出现了
签名失败的红色错误消息 flash[:error] = "Sign in with Twitter failed"
我还在CSS中发现了使其变为红色的类。我想在其他地方使用这个错误信息,但我有问题。
例如,当我尝试这样做
redirect_to show_path, flash[:error] => "Twitter's saying you're trying to post the same message twice"
就是不把消息发布到Twitter上,也不给出错误消息。当我改变=>
到=
它打破了整个应用程序(当我试图发布两次)给我这个消息:
can't convert Symbol into String
更奇怪的是(对我来说),我对通知没有问题。
redirect_to show_path, :notice => "Your Tweet was posted!"
有人能解释一下为什么会这样吗?这是GitHub上的项目
请注意,在您的示例中,您如何在redirect_to的散列参数中使用原始:notice
符号而不是flash[:notice]
。在你的代码与错误的闪光,你试图使用flash[:alert]
。你只需要传递符号,所以试试
redirect_to show_path, :error => "Twitter's saying you're trying to post the same message twice"
您还可以在redirect_to调用之前设置警报闪光:
flash[:error] = "Twitter's saying you're trying to post the same message twice"
redirect_to show_path
是啊,我也经历过。
@jsinger部分正确。您需要传递一个符号而不是flash[]
哈希值。但是有一个问题:redirec_to只支持两个速记符号::notice
和:alert
。还有第三个,一个通用的::flash
.
redirect_to show_path, :flash => { :success/:error/:whatever => "your flash message" }
我想知道这背后的原因。
APIdock
你试过了吗?
闪光。现在[:notice] = "some text"