在Rails中最方便集成使用Bootstrap的方式

创建项目

1
rails new BootstrapProject

创建模型

1
rails g scaffold xxx --skip-stylesheets

运行迁移

1
rake db:migrate

如果项目和模型都已经建立好了并已经运行了迁移,那么可以省略以上步骤,直接进入下面的流程

在Gemfile中添加bootstrap,这里使用twitter-bootstrap-rails

1
2
3
4
gem 'jquery-rails'
gem 'less-rails'
gem 'therubyracer'
gem 'twitter-bootstrap-rails'

bundle

1
bundle install

安装bootstrap

1
rails g bootstrap:install

在模型上运用bootstrap

1
rails g bootstrap:themed xxx -f

注:xxx可以是任意的模型,例如模型名称是Article,那么这里的语句就是:

1
rails g bootstrap:themed Articles 

还要在application.js中加上引用,否则bootstrap的一些按钮会失效:

1
2
//= require jquery
//= require twitter/bootstrap

Enjoy it~

反汇编技术笔记-基础知识 各种环境下搭建ruby on rails开发环境
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×