Rails 在ubuntu上安装rails(rvm ruby gem Bootstrap bootswatch)

ubuntu-14.04.5-desktop-amd64

ruby 2.2.0

rails 4.1.4

提示:复制粘贴命令,执行报错就手动输入命令

1. 下载源设置成mirrors.aliyun.com/ubuntu 记得reload

2. install rvm

ubuntu有自己的安装方式(curl方式会报pgp相关错误)
ubuntu install rvm 安装方式https://github.com/rvm/ubuntu_rvm

rvm安装完时的提示:

* First you need to add all users that will be using rvm to 'rvm' group,
and logout - login again,anyone using rvm will be operating with `umask

u=rwx,g=rwx,o=rx`.

* To start using RVM you need to run `source /etc/profile.d/rvm.sh`
in all your open shell windows,in rare cases you need to reopen all shell windows.
提示:terminal rvm: command not found 可以输入/bin/bash -login

执行下rvm -v察看版本

rvm 1.27.0 (manual) by Wayne E. Seguin <wayneeseguin@gmail.com>,Michal Papis <mpapis@gmail.com> [https://rvm.io/]

rvm安装完成

rvm说明https://ruby-china.org/wiki/rvm-guide

3.install ruby

在安装ruby之前执行下rvm list known察看可以安装的ruby版本

rvm install 2.2.0可以指定某个版本安装

安装完成后 rvm list察看下版本

如果有多个版本使用rvm use x.x.x切换版本 (rvm use 2.2.0 --default指定默认版本)

ruby -v察看ruby版本

ruby安装完成

安装方式和管理系统https://www.ruby-lang.org/zh_cn/documentation/installation/

4.安装rails

gem insatll rails -v 4.1.4 --no-ri --no-rdoc

显示:

Successfully installed rails-4.1.4
24 gems installed


rails -v 察看下版本

安装完成

5.启动rails

rails new app 新建项目

cd app 进入项目文件夹

如果显示:

********************************************************************************
* NOTICE *
********************************************************************************
* RVM has encountered a new or modified .rvmrc file in the current directory,*
* this is a shell script and therefore may contain any shell commands. *
* *
* Examine the contents of this file carefully to be sure the contents are *
* safe before trusting it! *
* Do you wish to trust '/home/tt/.rvmrc'? *
* Choose v[iew] below to view the contents *
********************************************************************************
y[es],n[o],v[iew],c[ancel]> n (输入n)

rails s 启动rails (rails s -p 9000指定端口)

显示:

=> Booting WEBrick
=> Rails 4.1.4 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
=> Ctrl-C to shutdown server
[2016-11-29 16:55:10] INFO WEBrick 1.3.1
[2016-11-29 16:55:10] INFO ruby 2.2.0 (2014-12-25) [x86_64-linux]
[2016-11-29 16:55:10] INFO WEBrick::HTTPServer#start: pid=10726 port=3000

在浏览器输入http://0.0.0.0:3000 显示Welcome aboard 欢迎页面




6.安装bootstrap
ruby-v察看版本(ruby2.2.0p0(2014-12-25revision49005)[x86_64-linux])
railsnewmyapp新建项目
cdmyapp进入项目文件夹
vigemfile编辑文件,增加一行gem'bootstrap-sass','~>3.3.5'
bundleinstall安装

设置
修改app/assets/stylesheets/application.css为app/assets/stylesheets/application.scss
并添加如下的代码来引用它
@import"bootstrap-sprockets";
@import"bootstrap";
("bootstrap-sprockets"的导入必须写在"bootstrap"和"bootstrap/variables"之前
删掉这个文件中所有的//require和//=require_tree标签,都改为@import来引用刚刚下载的zip包里的sass文件。不使用//require是因为这样就无法访问bootstrap的混合类型和变量。)

在app/assets/javascripts/application.js中添加对bootstrapjs的引用:
//=requirejquery
//=requirebootstrap-sprockets
完成设置

railsgscaffoldproductnameprice:decimaldescription:text创建表
rakedb:migrate更新数据库
railss启动rails
http://0.0.0.0:3000/products显示默认创建的页面

myapp/views/products/index.html.erb在页面最后增加以下代码(刷新页面,在下一步安装bootswatch后样式会有改变)

<divclass="container">
<divclass="jumbotron">
<h1>我的第一个Bootstrap页面</h1>
<p>重置窗口大小,查看响应式效果!</p>
</div>
<divclass="row">
<divclass="col-sm-4">
<h3>Column1</h3>
<p>学的不仅是技术,更是梦想!</p>
<p>再牛逼的梦想,也抵不住你傻逼似的坚持!</p>
</div>
<divclass="col-sm-4">
<h3>Column2</h3>
<p>学的不仅是技术,更是梦想!</p>
<p>再牛逼的梦想,也抵不住你傻逼似的坚持!</p>
</div>
<divclass="col-sm-4">
<h3>Column3</h3>
<p>学的不仅是技术,更是梦想!</p>
<p>再牛逼的梦想,也抵不住你傻逼似的坚持!</p>
</div>
</div>
</div>

安装bootstrap参考网站:
http://www.bootcss.com/
http://v3.bootcss.com/getting-started/#download
https://github.com/twbs/bootstrap-sass#a-ruby-on-rails
http://www.runoob.com/bootstrap/bootstrap-intro.html

bootstrap定制:
http://v3.bootcss.com/customize/

7.安装bootswatch
在gemfile增加gem'bootswatch-rails'
bundleinstall安装

设置
修改app/assets/stylesheets/application.scss为app/assets/stylesheets/application.css.scss
替换之前的2个@import
//Importbootstrap-sprockets
@import"bootstrap-sprockets";
//Importceruleanvariables
@import"bootswatch/cerulean/variables";
//Thenbootstrapitself
@import"bootstrap";
//Bootstrapbodypaddingforfixednavbar
body{padding-top:60px;}
//Andfinallybootswatchstyleitself
@import"bootswatch/cerulean/bootswatch";
//Whateverapplicationstylesyouhavegolast
@import"base";

新建app/assets/stylesheets/base.css.scss
完成设置

railss启动
http://0.0.0.0:3000/products刚才的样式改变了

新的模板:
将app/views/layouts/application.html.erb其中<body></body>,替换为https://github.com/scottvrosenthal/twitter-bootswatch-rails/blob/master/lib/generators/bootswatch/layout/templates/layout.html.erb中
<body><div>包括这里所有</div><%%=yield%></body>

刷性页面,Bootstraptheme这行是蓝色,完成

备注:更新gem

gem -v 察看版本默认2.4.6

gem update --system 更新为2.6.8


备注:gem -v察看版本(2.4.6)

gem server会启动127.0.0.1:8808 (RubyGems Documentation)

gem environment 安装路径说明

https://www.ruby-lang.org/zh_cn/libraries/ gem详细说明

https://gems.ruby-china.org/gem详细说明

https://ruby-china.org/wiki/rvm-guide了解gemset

相关文章

文章浏览阅读2.3k次,点赞4次,收藏22次。最近安装了CARLA预...
文章浏览阅读6.3k次,点赞5次,收藏15次。在清华镜像中下载U...
文章浏览阅读5k次。linux环境, python3.7.问题描述: 安装...
文章浏览阅读4.2k次,点赞4次,收藏17次。要安装这个 standa...
文章浏览阅读894次,点赞51次,收藏31次。在安卓使用vscode主...