Step 1. 使用bootstrap3
的gem
https://github.com/twbs/bootstrap-sass/
Step 2. 新增-导航头部
app/views/common/_navbar.html.erb
<!-- .navbar——设置nav元素为导航条组件 -->
<!-- .navbar-default——指定导航条组件为默认主题;-->
<nav class="navbar navbar-default" role="navigation">
<!-- .container-fluid——设置宽度充满父元素,即为100%;-->
<div class="container-fluid">
<!--.navbar-header——主要指定div元素为导航条组件包裹品牌图标及切换按钮; -->
<div class="navbar-header">
<!-- .navbar-brand——设置导航条组件内的品牌图标; -->
<a class="navbar-brand" href="/">项目名称</a>
</div>
<!-- .collapse——设置div元素为视口大于768px时显示; -->
<!-- .navbar-collapse——设置div元素为导航条组件各列表项的父元素; -->
<!-- bs-example-navbar-collapse-1是指折叠的目标; -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li>
<%= link_to("登入", '#') %>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
Step 3. 新增-页脚
app/views/common/_footer.html.erb
<footer class="container" style="margin-top: 100px;">
<p class="text-center">
Copyright ©<%= Time.now.year %> 项目名称
<br>
Design by flyweights
</p>
</footer>
Step 4. 修改-默认模板
app/views/layouts/application.html.erb
<!DOCTYPE html>
<html>
<head>
<title>Rails101</title>
<%= csrf_meta_tags %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
<body>
<div class="container-fluid">
<%= render "common/navbar" %>
<%= yield %>
</div>
<%= render "common/footer" %>
</body>
</html>
Step 5. 首页访问
$ rails g controller welcome
app/views/welcome/index.html.erb
<h1> Hello World! </h1>
config/routes.rb
Rails.application.routes.draw do
root 'welcome#index'
end
$ rails s
Step 6. 存档
$ git add .
$ git commit -m "add bootstrap html"
网友评论