Flash和redirect_to在一行中不产生闪存

jas*_*328 2 controller ruby-on-rails view ruby-on-rails-3 slim-lang

我有以下代码

redirect_to questionnaire_url, error: "Now please fill in the questionnaire."
Run Code Online (Sandbox Code Playgroud)

通常,如果我flash[:notice]在重定向之上设置一个值,闪存会显示在我的页面上,但是当我使用上面的代码时,它不会.

我显示闪光灯的代码是

- flash.each do |key, value|
  = content_tag(:div, value, class: "alert alert-#{key}")
Run Code Online (Sandbox Code Playgroud)

写完之后= flash.inspect我收到了

#<ActionDispatch::Flash::FlashHash:0x000000044322f0 @used=#<Set: {}>, @closed=false, @flashes={}, @now=nil>
Run Code Online (Sandbox Code Playgroud)

这当然是使用SLIM模板语言编写的.我的问题是notice实际生产的内容以及如何调整代码来修复它?谢谢.

Pin*_*nyM 7

原因是因为只有alert并且notice可以redirect_to使用此语法内联.对于任何其他闪存密钥,您需要指定:

redirect_to questionnaire_url, flash: {error: "Now please fill in the questionnaire."}
Run Code Online (Sandbox Code Playgroud)