RailsCasts18 Looping Through Flash 使用循环展现flash
来源:互联网 发布:崩坏3矩阵空间 编辑:程序博客网 时间:2024/06/06 07:05
有时layout文件中会展示几种flash messages;每种flash在展现前均会判断是否为nil,则均需要花费3行代码,如下:
ruby<html> <!-- (head snipped) --> <body> <h1>ASCIIcasts</h1> <% unless flash[:notice].nil? %> <div id="notice"><%= flash[:notice] %></div> <% end %> <% unless flash[:notice].nil? %> <div id="notice"><%= flash[:notice] %></div> <% end %> <%= yield %> </body></html>使用循环可有效的减少代码量,如下:
<% flash.each do |key,msg| %> <%= content_tag :p, msg, :id => key %><% end %>
content_tag需要3个参数,第一个为element的名字,第二个为element的start、end标签中的内容,第三个参数为hash,规定element的属性。与之前的代码相比,现在的代码量是更小的,且灵活的。
原文:http://railscasts.com/episodes/18-looping-through-flash?view=asciicast
0 0
- RailsCasts18 Looping Through Flash 使用循环展现flash
- jasperreports报表Flash展现
- flash 循环
- Spring MVC使用Flash Attribute展现提示消息
- flash循环播放
- flash中循环例子
- Flash 8:使用Flash Lite
- Flash
- flash
- flash
- Flash
- flash
- Flash
- flash
- FLASH
- FLASH
- flash
- FLASH
- C++ primer 第五版 中文版 练习 9.47 个人code
- sql sever 2008在vs2010
- Android获取当前激活Activity
- 内存:栈与堆
- 写在开始,追梦
- RailsCasts18 Looping Through Flash 使用循环展现flash
- Zoj1201
- C语言产生随机数
- cocos2d-x 3.0 背景音乐与音效
- 小黑小波比.nodejs技巧
- 运筹学在七十年代的失败
- ORACLE 数据库导入、导出(备份、恢复)
- Linux 中页的回收
- 10个强大的Apache开源模块