`
helloqidi
  • 浏览: 11904 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

beast学习笔记——6,application.html.erb

    博客分类:
  • ROR
阅读更多

beast学习笔记——6,application.html.erb

 
1/此模版的整体布局:
<div id="header"></div>
<div id="container">
  <div id="content"></div>
  <div id="right"></div>
</div>
<div id="footer"></div>
 
2
(1)代码
<%= render :partial => "layouts/head" %>
(2)表示
render引用局部模版
 
3
(1)代码
<%= content_tag 'p', h(flash[:notice]), :class => 'notice' if flash[:notice] %>
(2)表示
【1】content_tag,生成一个HTML标签,例如:

content_tag(:p, "Hello world!")   
# => <p>Hello world!</p>  
content_tag(:div, content_tag(:p, "Hello world!"), :class => "strong")   
# => <div class="strong"><p>Hello world!</p></div>  
content_tag("select", options, :multiple => true)  
 # => <select multiple="multiple">...options...</select>
 
【2】h,完整名字html_escape(),用于HTML转义,使显示文本而不是HTML。需要养成习惯,写完“<%=”紧跟着写“h(”。
【3】flash[:notice],显示错误信息
 
4
(1)代码
<%= yield %>
<%= yield :right %>
(2)表示
【1】yield,用于模版文件中调用内容,如果后面没有接内容,则是调用默认的view,即index.html.erb文件
【2】yield :right,表示调用使用 content_for隐藏的内容,该内容的名字为right。可以在index.html.erb中找见:
<% content_for :right do %>
......
<% end %>
content_for,用于保存内容,并在yield调用时显示。

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics