Rails flash.now 具有任意密钥的哈希值?
所以我正在做一些基本的验证并尝试向闪存哈希添加任意密钥(你可以这样做吗?)
所以在我的控制器中我有这个...“previousaction”帖子到此页面。
if params[:home_value] == "Select One"
flash.now[:home_value] = "Please select a home value"
render "previousaction"
else
#set controller vars.. render this action as normal
end
在视图中:
<% if home_value %>
<h6 id="notice" style="color:red;padding-bottom:5px;"><%= home_value %></h6>
<%= label_tag "Estimated Home Value", "Estimated Home Value", :style => "color:red;"%><br/>
<% else %>
<%= label_tag "Estimated Home Value", "Estimated Home Value" %><br/>
<% end %>
但是在尝试加载控制器操作(第一次)时出现此错误:
未定义的局部变量或方法“home_value”
提示:)
对于戴夫:
在之前的操作/视图中,我使用 flash[:notice ]像这样:
if params[:zip_code].length != 5
flash.now[:notice] = "Invalid zipcode. Please enter your 5-digit zipcode"
render "firstpage"
else
然后在视图中
<% if notice %>
flash[:notice]是rails的特殊flash键吗?
So I'm doing some basic validation and trying to add an arbitrary key to the flash hash (you can do that right?)
So in my controller I have this... "previousaction" posts to this page.
if params[:home_value] == "Select One"
flash.now[:home_value] = "Please select a home value"
render "previousaction"
else
#set controller vars.. render this action as normal
end
And in the view:
<% if home_value %>
<h6 id="notice" style="color:red;padding-bottom:5px;"><%= home_value %></h6>
<%= label_tag "Estimated Home Value", "Estimated Home Value", :style => "color:red;"%><br/>
<% else %>
<%= label_tag "Estimated Home Value", "Estimated Home Value" %><br/>
<% end %>
But I get this error when trying to load the controller action (the first time):
undefined local variable or method `home_value'
Tips appreciated :)
For Dave:
In a previous action/view I use flash[:notice] like this:
if params[:zip_code].length != 5
flash.now[:notice] = "Invalid zipcode. Please enter your 5-digit zipcode"
render "firstpage"
else
and then in the view
<% if notice %>
Is flash[:notice] a special flash key for rails?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
home_value
不会神奇地与flash
关联,它只是被视为局部变量;尝试直接使用:home_value
访问 flash 哈希。也就是说,使用任意密钥的目的是什么?
home_value
won't magically be associated with theflash
, it's just being treated as a local variable; try accessing the flash hash with:home_value
directly.That said, what's the purpose of using an arbitrary key?