bootstrapを使ってみる

参考

Ruby on Rails 3.2.10でとりあえずプロジェクト立ち上げるメモ
http://qiita.com/items/e2427141443a90d66a35

Gehirn RS2 に nginx + unicorn 環境で Rails3 を動かしてみる("おまけ" twitter-bootstrap-rails も動かしてみよう)
http://qiita.com/items/c1edfa84b34dba2211ac

インストール

/mnt/hgfs/railsを共有フォルダとしたのでここで作っていきます

rails new bootstrap
cd bootstrap

bootstrapつかうよーとGemfileに書いて

gem "twitter-bootstrap-rails"

bundle install

すると

sqlite3がないよ とか言われるので

sudo apt-get install -y sqlite3 libsqlite3-dev
gem install sqlite3 -v '1.3.7'

再度 bundle install

bundle install

意気揚々と

rails g bootstrap:install

とかやると

/.rvm/gems/ruby-1.9.3-p392/gems/execjs-1.4.0/lib/execjs/runtimes.rb:51:in `autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)

みたいに怒られます

どうやらランタイムエンジンがないよ ということで

ExecJS supports these runtimes:

therubyracer - Google V8 embedded within Ruby

therubyrhino - Mozilla Rhino embedded within JRuby

Node.js

Apple JavaScriptCore - Included with Mac OS X

Microsoft Windows Script Host (JScript)

のどれかをつかえってことなんですけど

定番?の therubyracerを使っていきます

http://qiita.com/items/e2427141443a90d66a35

Gemfileに

gem 'execjs'
gem 'therubyracer'
gem "less-rails" #Sprockets (what Rails 3.1 uses for its asset pipeline) supports LESS

とかいて

bundle install
rails g bootstrap:install less

うまく

insert app/assets/javascripts/application.js
create app/assets/javascripts/bootstrap.js.coffee
create app/assets/stylesheets/bootstrap_and_overrides.css.less
create config/locales/en.bootstrap.yml
gsub app/assets/stylesheets/application.css
gsub app/assets/stylesheets/application.css

とかでたら成功です

設定

レイアウトファイル生成

rails g bootstrap:layout application fluid

ページ作成

rails g scaffold Post title:string description:text
rake db:migrate
rails g bootstrap:themed Posts

route変更

vim config/routes.rb

root :to => 'posts#index'

デフォルトファイル削除

rm -f public/index.html

起動

rails s

TIPS

cannot load such file -- less
(in /mnt/hgfs/rails/bootstrap/app/assets/stylesheets/bootstrap_and_overrides.css.less)

って怒られるときは

gem "less-rails" #Sprockets (what Rails 3.1 uses for its asset pipeline) supports LESS