rails3 使用bootstrap step by step


rails3 使用bootstrap

一,背景:

  这个不多说,最好的就是看文档http://twitter.github.com/bootstrap/

  本文例子github链接  testbootstrap

  git 地址git@github.com:Ryan007/testbootstrap.git

二,使用方法:

  本人用的使rails3.2.12应该是比较新的版本:

  step1:在gemfile里添加twitter的gem包支持,然后bundle install

  1. gem 'libv8''~> 3.11.8'  
  2. gem 'less-rails'  
  3. gem 'twitter-bootstrap-rails'  
  4. gem 'formtastic'  

step2:在你的application.js中添加

  1. //= require twitter/bootstrap  

step3:生成你的model,修改相应的rails配置文件

  1. rails g scaffold people name:string weight:decimal desc:text  --skip-stylesheets  
  2. rake db:create  
  3. rake db:migrate  
  1. rm public/index.html   

修改routes.rb
  1. root :to =>"people#index"  
step 4:启动你的rails应用,在地址栏中访问:

这时候看到的跟平常的一样

  1. rails server  
step 5:见证神奇:

执行下面命令,生成css代码

  1. rails g bootstrap:install  
  2. rails g bootstrap:themed people -f  
step 6:启动你的rails应用,在地址栏中访问:
  1. rails server  

的确不一样啦

三,稍微复杂的配置:


step1: 修改layout/application.html.erb,加载css
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4.   <title>Testbootstrap</title>  
  5.   <%= stylesheet_link_tag    "application":media => "all" %>  
  6.   <%= javascript_include_tag "application" %>  
  7.   <%= csrf_meta_tags %>  
  8. </head>  
  9. <body>  
  10.   
  11. <div class="navbar navbar-fixed-top">  
  12.     <div class="navbar-inner">  
  13.       <div class="container">  
  14.         <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">  
  15.           <span class="icon-bar"></span>  
  16.           <span class="icon-bar"></span>  
  17.           <span class="icon-bar"></span>  
  18.         </a>  
  19.         <a class="brand" href="#">My Link</a>  
  20.         <div class="nav-collapse">  
  21.           <ul class="nav">  
  22.             <li><%= link_to "Link", root_url %></li>  
  23.             <li><%= link_to "Link" %></li>  
  24.             <li><%= link_to "Link" %></li>  
  25.             <li><%= link_to "Link" %></li>  
  26.           </ul>  
  27.         </div>  
  28.       </div>  
  29.     </div>  
  30.   </div>  
  31.   
  32.   <div class="container">  
  33.     <div class="row">  
  34.       <div class="span9"><%= yield %></div>  
  35.       <div class="span3">  
  36.         <h2>About Us</h2>  
  37.         The Baidu Story  
  38.   
  39.         Our name was inspired by a poem written more than 800 years ago during the Song Dynasty. The poem compares the search for a retreating beauty amid chaotic glamour with the search for one's dream while confronted by life's many obstacles. "…hundreds and thousands of times, for her I searched in chaos, suddenly, I turned by chance, to where the lights were waning, and there she stood." Baidu, whose literal meaning is “hundreds of times”, represents a persistent search for the ideal.  
  40.       </div>  
  41.     </div>  
  42.   </div>  
  43.   
  44. </body>  
  45. </html>  

setp2:,让你的样式更好看

修改bootstrap_and_overrides.css.less,添加

  1. bootstrap_and_overrides.css.less 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值