First, let's see a sample layout file in rails, and explain it step by step:
<!DOCTYPE html> <html> <head> <title><%= title %></title> <%= csrf_meta_tag %> <!--[if lt IE 9]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <%= stylesheet_link_tag 'blueprint/screen', :media => 'screen' %> <%= stylesheet_link_tag 'blueprint/print', :media => 'print' %> <!--[if lt IE 8]><%= stylesheet_link_tag 'blueprint/ie' %><![endif]--> <%= stylesheet_link_tag 'custom', :media => 'screen' %> </head> <body> <div class="container"> <header> <%= image_tag("logo.png", :alt => "Sample App", :class => "round") %> <nav class="round"> <ul> <li><%= link_to "Home", '#' %></li> <li><%= link_to "Help", '#' %></li> <li><%= link_to "Sign in", '#' %></li> </ul> </nav> </header> <section class="round"> <%= yield %> </section> </div> </body> </html>
1. rails 3 use html5 as default, as indicated in <!DOCTYPE html>
2. since html5 is too new, some old IE browsers like IE8 don't support totally support it, so we include some javascript code (known as "html5shiv")to work around it.
<!--[if lt IE 9]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]-->
this code piece is weird.
it means, this line of script including will only be included if IE version is less than IE9.
[if lt IE 9] is not rails, it is conditional comment supported only by IE. This purpose is just supplying a way to provide code that only work in IE, not any other browsers. This is very useful
3. then
<!--[if lt IE 8]><%= stylesheet_link_tag 'blueprint/ie' %><![endif]-->
works the same way, if current browser less than IE8, it will include another css file.
This css file fixed many IE-only issues.
4. next, we include another css file, called "custom", to put your custom css, we haven't created it yet.
css is forgiving, even if there is no this file, our page still work fine.
5.next, we put all the contents in to a container div,
<div class="container">
</div>
This is needed by blueprint,
the div tag in html is a generic division, it does nothing but divding the doc into distinct part.
in older html, div tags are used for nearly all site divisions, but html5 adds the "header", "nav" and "section" elements, for divisions common to many apps.
then, there are header and section elements, the header contains the site navigation(nav),
the section element contains the site's main content.
all html elements, including divs and the new html5 elements, can be assigned classed and ids.
these are merely labels, and are useful for styling with CSS. The main differences between classes and ids is that classed can be used multiple times on a page, but ids can only be use once.
<img alt="Sample App" class="round" src="/images/logo.png" />
6. inside the header is a rails helper called "image_tag"
<%= image_tag("logo.png", :alt => "Sample App", :class => "round")%>
note, we also passed a hash as second param,
let's see the html generated:
<img alt="Sample App" class="round" src="/images/logo.png" />
the alt attr is what will be displayed if there is no image.
a. you can see for a img tag, it is not <img></img>
instead, it is <img ....... />
this kind of tag are known as self-closing tags.
b. the alt attr is optional, if you don't specify this param, rails will auto use the file name of the image file, if image doesn't display.
c. rails helpers ofter take options hashes in this way, giving us the flexibility to add arbitrary html options without ever leaving Rails!
7. next is a list of navigation links, using unordered list tag <ul>
link_to is a rails helper to creat links, which will create <a href=""></a> as html.
the 1st argument is the link text.
the 2nd argument is the url, for now we just use "#" means blank link, link to itself. we will fill it with useful url later.
the generated html will be
<nav class="round"> <ul> <li><a href="#">Home</a></li> <li><a href="#">Help</a></li> <li><a href="#">Sign in</a></li> </ul> </nav>
发表评论
-
12.3.3 scaling issue of the status feed
2011-10-30 17:54 814the problem of the implementati ... -
12.3 the status feed
2011-10-30 15:34 8521. we need to get all the micro ... -
12.2 a working follow button with Ajax
2011-10-29 18:10 9091. in the last chapter, in the ... -
12.2 a web interface for following and followers.
2011-10-28 22:14 8761.before we do the UI, we need ... -
12. following user, 12.1 relationship model
2011-10-18 14:29 7471. we need to use a relationshi ... -
11.3 manipulating microposts.
2011-10-17 15:31 8931. since all micropost actions ... -
11.2 show microposts.
2011-10-17 12:01 6981. add test to test the new use ... -
11.1 user micropost -- a micropost model.
2011-10-17 10:43 11031. we will first generate a mic ... -
10.4 destroying users.
2011-10-16 15:47 733in this chapter, we will add de ... -
10.3 showing users list
2011-10-15 20:41 768in this chapter, we will do use ... -
10.2 protect pages.
2011-10-15 15:11 656again, we will start from TD ... -
10.1 updating users.
2011-10-14 18:30 7051. git checkout -b updating-use ... -
9.4 sign out
2011-10-13 15:21 731whew!!!, last chapter is a long ... -
9.3 sign in success.
2011-10-12 15:39 7411. we will first finish the cre ... -
9.1 about flash.now[:error] vs flash[:error]
2011-10-12 15:37 722There’s a subtle difference ... -
9.2 sign in failure
2011-10-12 12:19 655start from TDD!!! 1. requir ... -
9.1 sessions
2011-10-12 10:00 643a session is a semi-permanent c ... -
what test framework should you use?
2011-10-11 16:56 0for integration test, i have no ... -
what test framework should you use?
2011-10-11 16:56 0<p>for integration test, ... -
8.4 rspec integration tests
2011-10-11 16:53 714in integration test, you can te ...
相关推荐
12. **Asset Pipeline**:Rails的资产管道负责处理CSS、JavaScript和其他静态资源,通过Sprockets编译和合并文件,实现压缩和缓存,提升应用性能。 13. **Heroku部署**:Rails应用可以便捷地部署到Heroku这样的云...
- **响应式设计**:通过媒体查询(Media Queries)和流式布局(Fluid Layout),CSS3支持创建自适应不同设备屏幕尺寸的网站,实现真正的响应式设计。 - **动画与过渡效果**:CSS3引入了`@keyframes`规则,允许...
- `public/`:静态资源文件,如CSS、JavaScript、图片等,对外直接可用。 - `spec/`:RSpec或其他测试框架的测试文件。 - `Gemfile`:定义项目依赖的Gem包。 - `Gemfile.lock`:记录具体版本的Gem包,确保部署时一致...
2. **定位机制**:CSS提供了三种定位机制:正常流(block layout)、浮动(float)和绝对定位(position: absolute)。正常流遵循从左到右、从上到下的排列方式;浮动用于创建多列布局,但可能导致父元素高度塌陷;...
Andy Rails工具箱 Andy Rails Toolbox包含许多有用的Rails开发帮助器。 安装 将此行添加到您的应用程序的Gemfile中: gem 'andy_rails_toolbox' 然后执行: $ bundle 或将其自己安装为: $ gem install andy_...
13. **布局(Layout)**: Rails中的布局定义了页面的通用结构,如头部和尾部。`app/views/layouts/application.html.erb`是默认布局。 14. **Bootstrap或Sass**: 示例应用可能使用Bootstrap库来快速创建响应式设计...
**Sharing Variables between the Templates and the Layout** 有时需要在不同的视图文件之间共享变量。可以通过实例变量或局部变量来实现。 **The ToDo List screen** 了解如何设计和实现 To-Do List 的主屏幕。...
4. 布局和部分视图:Rails支持布局(Layout)和部分视图(Partial),用于页面结构的复用。 5. 表单处理:使用FormHelper生成表单元素,处理用户输入,与控制器的行动关联。 6. 测试驱动开发:Rails鼓励TDD(Test-...
该项目是通过引导的。 您将在下面找到一些有关如何执行...Ruby on Rails 在开发中代理API请求 配置代理后出现“无效的主机头”错误 手动配置代理 配置WebSocket代理 在开发中使用HTTPS 在服务器上生成动态<met
#KAdmin 此 Rails 引擎为您提供构建具有以下外观和感觉的 CMS 所需的工具: : 该项目使用 KAdmin 的扩展许可证 为了为 CMS 提供外观和感觉包装器,您必须指定布局并包含帮助程序: class ItemsController <...
Ruby on Rails 在开发中代理API请求 配置代理后出现“无效的主机头”错误 手动配置代理 配置WebSocket代理 在开发中使用HTTPS 在服务器上生成动态<meta>标记 预渲染为静态HTML文件 将数据从服务器注入
4. **布局技术**:CSS提供了多种布局方式,如流体布局、网格布局(CSS Grid)、Flexbox(弹性盒子)和最近的CSS Layout Module Level 3(CSS 模块布局)。 5. **响应式设计**:使用 `@media` 查询,CSS可以根据设备...
头等舱 部署的URL: : 概述 NCfirstclass允许用户下订单,该订单将由管理员处理,以将产品交付给用户。 管理员将能够查看用户信息,已订购产品的名称以及其商品代码,如果是在库存中则要发货,如果不是,则...|__ css/
在Ruby on Rails中,开发者通常使用Markdown或HTML来编写内容,CSS和JavaScript来处理样式和交互,而Ruby则用于后端逻辑和数据库交互。yzclaire.github.io-master这个文件名表示这是项目的主要分支,可能是GitHub...
要更改布局和设计,请在railsapps.github.io.wiki存储库中编辑_Layout.html文件以及CSS和Javascript。 然后,使用位于gem从Wiki生成静态网页。 要提交生成的网页,您需要拥有组织团队成员的存储库读写权限。 目标 ...
它提供了一套DOM操作API和事件处理机制,作为核心框架,支撑了一系列的JavaScript扩展库,成为了许多开发者首选的底层框架,尤其是在Ruby on Rails中的广泛应用。Scriptaculous即基于Prototype,用于实现各种JS组件...
- "webContentProviders"、"ResourceManager"、"Layoutfiles"、"NotificationManager"、"ActivityManager"等词汇是Android系统中常见的组件和管理器,用于管理应用的内容、资源、布局、通知和活动。 - "AndroidC/...
- **Block Elements/Inline Elements/Giving Elements Layout**:介绍如何使用CSS布局元素。 通过上述知识点的总结,我们可以看到Script.aculo.us不仅提供了丰富的视觉效果,还集成了实用的UI控制组件,使得开发者...
" Liquid "是Shopify的默认模板语言,由Ruby on Rails社区开发。这是一种动态、声明式的标记语言,专门用于构建Shopify商店的前端界面。 Liquid设计的目标是安全,确保即使在用户输入的数据被渲染时,也不会对服务器...
接着,在你的Phoenix项目的`web/templates/layout/application.html.eex`或相应的布局文件中,引入`font_awesomex`的CSS样式表。这样,你的应用就能识别并正确显示所有的Font Awesome图标。 在实际开发中,`font_...