博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【转】Rails 4中使用 Bootstrap 3
阅读量:5258 次
发布时间:2019-06-14

本文共 2231 字,大约阅读时间需要 7 分钟。

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  from , 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  and you can download the latest version . 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  to your rails application without a gem. There is also a sample application on Github, you can .

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

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

 
 
 

转载于:https://www.cnblogs.com/zs-note/p/4527998.html

你可能感兴趣的文章
GitLab could not read Username for 'ip地址':No such device or address
查看>>
sql server 2012使用新特性offset和fetch next完成分页操作
查看>>
Element-ui安装与使用(网站快速成型工具)
查看>>
day012生成器函数、生成器表达式、列表推导式
查看>>
游戏产品前期提案审案流程
查看>>
iOS 如何监听用户在手机设置里改变了系统的时间?
查看>>
C++指针引发的巨大谜题
查看>>
linux内核学习:进程调度
查看>>
typedef 用户自定义的数据类型取一个新的名字
查看>>
TOMCAT内存大小调整
查看>>
打开指定文件或文件夹
查看>>
tomcat 配置图片虚拟路径不起作用解决办法
查看>>
如何查询收发的短信息
查看>>
UVA 111 简单DP 但是有坑
查看>>
Mysql 数据库操作
查看>>
Python OS模块
查看>>
Python item的使用
查看>>
Java关键字:transient,strictfp和volatile简介
查看>>
SQL表中的自连接定义与用法示例
查看>>
hdu 1032 The 3n + 1 problem
查看>>