If you are looking to use Bootstrap 3 with Rails, then this article is for you. It provides a guide to adding Bootstrap 3, aka Twitter Bootstrap 3, to a new Rails 4 project. I found this article from Eric Minkel, however I’ve deviated slightly from his implementation and I decided to document it.

Let’s start by creating a new project:

rails new bootstrap

Next, we need Bootstrap 3 and you can download the latest version here. At the time this article was written, the latest Bootstrap release was v3.0.2.

I’m only interested in using the minimized Bootstrap files. We need to copy a number of files into our project from the Bootstrap download:

  1. Copy bootstrap.min.css to the /vendor/assets/stylesheets directory
  2. Copy bootstrap.min.js to the /vendor/assets/javascripts directory
  3. Copy the fonts directory and its contents to /vendor/assets/

Now that the files have been added to your project. We need to tell the application to use them.

Edit app/assets/stylesheets/application.css and add *= require bootstrap.min along with some @font-face overrides which change the path to the glyphicons. We’ll do that here to avoid changing the bootstrap files.

*= require bootstrap.min
*= require_self
*= require_tree .
*/ @font-face {
font-family: 'Glyphicons Halflings';
src: url('../assets/glyphicons-halflings-regular.eot');
src: url('../assets/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'),
url('../assets/glyphicons-halflings-regular.woff') format('woff'),
url('../assets/glyphicons-halflings-regular.ttf') format('truetype'),
url('../assets/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg');
}

Next, we need to edit app/assets/javascripts/application.js and add//= require bootstrap.min. Here’s a look at mine:

//= require jquery
//= require jquery_ujs
//= require bootstrap.min
//= require turbolinks
//= require_tree .

That is all it takes to add Bootstrap 3 to your rails application without a gem. There is also a sample application on Github, you can download it here.

I also recently published a new article that builds on this project. In it, I show you how to build the Bootstrap jumbotron in Rails. Check it out here.

If you have any suggestions or feedback, please let me know in the comments, via email or onTwitter.

 
 
 

【转】Rails 4中使用 Bootstrap 3的更多相关文章

  1. Ruby Rails学习中:注册表单,注册失败,注册成功

    接上篇 一. 注册表单 用户资料页面已经可以访问了, 但内容还不完整.下面我们要为网站创建一个注册表单. 1.使用 form_for 注册页面的核心是一个表单, 用于提交注册相关的信息(名字.电子邮件 ...

  2. Ruby Rails学习中:调试信息和 Rails 的三种环境,Users 资源,调试器,Gravatar 头像和侧边栏

    注册 一.调试信息和 Rails 环境 现在咱们要实现的用户资料页面是我们这个应用中第一个真正意义上的动态页面.虽然视图的代码不会动态改变, 不过每个用户资料页面显示的内容却是从数据库中读取的.添加动 ...

  3. Django中使用Bootstrap

    一.在Django中引用Bootstrap模版 1.首先下载bootsrtap代码(http://v3.bootcss.com/getting-started/#download),并将下载后的文件放 ...

  4. 在ASP.NET MVC中使用 Bootstrap table插件

    Bootstrap table: http://bootstrap-table.wenzhixin.net.cn/zh-cn/getting-started/ 1. 控制器代码: using Syst ...

  5. vue-cli+webpack在生成的项目中使用bootstrap

    在也个html页面中加入bootstrap是很方便,就是一般的将css和js文件通过Link和Script标签就行. 那么在一个用vue-vli生成的前端项目中如何加入?因为框架不一样了,略微要适应一 ...

  6. Vue中引入bootstrap导致的CSS问题

    最近在进行vue.js+webpack进行模块化开发的时候,遇到一个奇怪的问题. 问题是这样的: 1. 在main.js文件中引入bootstrap的js和css. 2. 自己写了一个Header.v ...

  7. 第87节:Java中的Bootstrap基础与SQL入门

    第87节:Java中的Bootstrap基础与SQL入门 前言复习 什么是JQ? : write less do more 写更少的代码,做更多的事 找出所有兄弟: $("div" ...

  8. 如何在jsp中引入bootstrap

    如何在jsp中引入bootstrap包: 1.首先在http://getbootstrap.com/上下载Bootstrap的最新版. 您会看到两个按钮: Download Bootstrap:下载 ...

  9. vue-cli+webpack在生成的项目中使用bootstrap的方法

    在一个html页面中加入bootstrap是很方便,就是一般的将css和js文件通过Link和Script标签就行.那么在一个用vue-vli生成的前端项目中如何加入?因为框架不一样了,略微要适应一下 ...

随机推荐

  1. echache缓存的简单使用方法

    1.需要echache的jar包 2.需要配置文件ehcache.xml和ehcache.xsd,主要是在ehcache.xml中进行配置 3.修改配置文件ehcache.xml  ,例如添加配置如下 ...

  2. 【bzoj3747】Kinoman[POI2015](线段树)

    题目传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3747 对于这种题,考虑固定区间的右端点为r,设区间左端点为l能取得的好看值总和为a[l] ...

  3. EntityFramework 学习 一 Colored Entity in Entity Framework 5.0

    You can change the color of an entity in the designer so that it would be easy to see related groups ...

  4. java基础(4)-数组(1)

    数组:存储同一种数据类型的多个元素的容器数组初始化: 元素类型[] 数组名 = new 元素类型[数组长度]int [] arr = new int[5] 元素类型[] 数组名 = new 元素类型[ ...

  5. http 常见的错误码

    翻译自:https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html 常见错误码 一.信息 1XX (Information 1xx) ——这一类的状 ...

  6. Codeforces Round #425 (Div. 2) D 树链剖分 + 树状数组维护区间

    一看就知道 可以LCA判断做 也可以树链剖分拿头暴力 然而快速读入和线段树维护区间会T70 于是只能LCA? 线段树的常数不小 于是需要另外一种办法来进行区间加减和查询区间和 就是使用树状数组 这个题 ...

  7. Qt QFileSystemModel QDirModel 示例代码, 使用方法

    1.  QFileSystemModel 查看,添加 和 删除目录 2. 实现代码 dialog.h #ifndef DIALOG_H #define DIALOG_H #include <QD ...

  8. Centos Crontab查看状态和开启

    # service crond status crond is stopped # service crond start Starting crond # service crond status ...

  9. redis 按空间范围查询点位

    GEORADIUS GEORADIUS key longitude latitude radius m|km|ft|mi [WITHCOORD] [WITHDIST] [WITHHASH] [ASC| ...

  10. APP Store审核太慢?大神分享快速审核的小技巧

    这节课要来跟大家讲讲怎样可以快速的有效的通过苹果的审核,大家可能也有听说过苹果的快审,苹果的审核流程除了机器审核还有一个人工的审核,以前的苹果审核时用到的时间也是不短,一些有经验的开发者可能也会发现在 ...