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

#008_layouts和content_for

阅读更多
如果我们希望在不同页面使用不同的样式,我们可以使用layouts + content_for,如第8行:
<!-- layouts/application.rhtml -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">   
<html>   
  <head>   
    <title>Todo List</title>   
    <%= stylesheet_link_tag 'application' %>   
    <%= yield :head %>   
  </head>   
  <body>   
    <div id="container">   
      <h1>Todo List</h1>   
      <%= yield %>   
    </div>   
  </body>   
</html>

在视图中使用content_for标签,即可实现在该不同视图根据需要调用不同样式的功能。
<!-- projects/index.rhtml -->
<% content_for :head do %>   
  <%= stylesheet_link_tag 'projects' %>   
<% end %>

<h2>Projects</h2>   
<ul>   
  <% for project in @projects %>   
    <li><%= project.name %></li>   
  <% end %>
</ul>

话说Ryan还和大家讨论在一个视图中连接多个CSS是否合适,当然,这是合理的,也能给我们的开发带来更多的灵活。
分享到:
评论

相关推荐

    Python代码源码-实操案例-框架案例-如何使用列表内容批量生成PowerPoint演示文稿中的幻灯片.zip

    for title, content in slide_content: slide = prs.slides.add_slide(blank_slide_layout) tf = slide.shapes.title tf.text = title body = slide.shapes.placeholders[1] tf2 = body.text_frame tf2.text...

    netWindows_0.3.0_pre2

    which can form the basis of many application interface layouts. Provides support for both horizontal and vertical splitting. - Combo Box widget: supports partial (incremental) option matching, first ...

    fio-devhub:FIO开发人员中心

    FIO开发人员中心入门网站布局: FIO-DEVHUB |-- _data (The yaml data used by the site) |-- _docs (The documentation pages) |-- _includes (Reusable html code) |-- _layouts (Layouts for different content ...

    Learn Java for Android Development_2nd.pdf

    ### Java for Android Development 第二版知识点概述 #### 一、书籍基本信息 - **书名**:《学习Java用于Android开发》第二版 - **作者**:Jeff Friesen - **出版社**:Apress - **版权信息**:本书版权所有,未经...

    ruby rails recipes

    本书包含的内容非常广泛,不仅覆盖了用户界面的设计与实现,还深入探讨了模型层和控制器层的最佳实践。为了更好地理解和应用这些技术方案,下面将对文档中的部分章节进行详细的解析。 #### 用户界面食谱 **1. 在位...

    Microsoft SharePoint 2010 Developer Reference

    - **Content:** Offers capabilities for managing documents, media, and other types of content. - **Search:** Enables powerful search functionalities within SharePoint sites. - **Insights:** Provides ...

    用python往ppt批量插入图片.rar

    在Python编程领域,批量处理是一项常见的任务,尤其在数据处理和自动化工作中。在这个场景中,我们需要使用Python来实现一个功能,即批量将图片插入到PowerPoint(PPT)文件中。这个过程涉及到对PPT文件的操作,这...

    Android Apps for Absolute Beginners

    本书《Android Apps for Absolute Beginners》旨在为初学者提供一个简单明了的指南,帮助他们理解并掌握Android应用开发的基本概念和技术。对于那些想要踏入移动应用开发领域但又对复杂的术语和技术感到迷茫的新手来...

    mcts70-515_microsoft_trainingkit.pdf

    - **Master Pages and Themes:** Design patterns for creating reusable layouts and styles, enhancing consistency and maintainability across web applications. - **Server Controls:** Built-in controls ...

    PhoneGap 3.x Mobile Application Development Hotshot.2014.pdf

    #### Book Content and Structure The book is structured around 12 projects that cover various aspects of mobile app development with PhoneGap 3.x. Each project focuses on a specific feature or ...

    Responsive.Web.Design.with.HTML5.and.CSS3.Essentials

    Design and deliver an optimal user experience for all devices About This Book Get to grips with the core functionality of RWD through examples Discover how to make layouts, content and media flexible,...

    Android 4.0 Compatibility Definition

    - **WebViewCompatibility**: WebView is a component that allows web content to be displayed within an application. Compatibility in this area ensures that WebView works consistently across devices. - *...

    smashing-ebooks-editors-choice-library-treat

    This eBook is a part of The Smashing Library, which bundles valuable content into a single package for readers interested in web design, user experience (UX), and related topics. Let's delve deeper ...

    Preparing Written Messages

    This includes using appropriate fonts, colors, and layouts. In IT, visual design is particularly important for creating user interfaces, infographics, and presentations that are engaging and easy to ...

    odoo themes

    This approach gave us the freedom to focus on the things that are really important for designers: styles, content, and the logic behind them. No more struggling with technical stuff. #### Default ...

    d3.js in action

    数据可视化,manning2015年新作,d3... Then, you'll explore practical techniques for content creation, animation, and representing dynamic data—including interactive graphics and data streamed live ove...

Global site tag (gtag.js) - Google Analytics