Mysql用database.ymlを生成する

rails new app_name

だと、databese.ymlの中身はsqlite3仕様になってる。
引数にオプションdとデータベース名を渡すと、そのデータベースのdatabase.ymlが出来上がる。

$rails new -d mysql

config/database.yml


# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MYSQL driver
# gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
# gem 'mysql2'
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: shern_development
pool: 5
username: root
password:
socket: /opt/local/var/run/mysql5/mysqld.sock

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: mysql2
encoding: utf8
reconnect: false
database: shern_test
pool: 5
username: root
password:
socket: /opt/local/var/run/mysql5/mysqld.sock

production:
adapter: mysql2
encoding: utf8
reconnect: false
database: shern_production
pool: 5
username: root
password:
socket: /opt/local/var/run/mysql5/mysqld.sock

http://www.rubylife.jp/rails/model/index2.html

おまけ

オプションtをつけると、testディレクトリを生成しない。

TwitterBootstrapのテーマをRailsアプリに適用する

環境

twitter-bootstrap-rails (2.1.7)
rails (= 3.2.6)
less-rails (2.2.6)
ruby 1.9.3p194

bootstrapテーマは以下とかからダウンロードできます。よく見ていませんが有料もあるようですが無料もあります。
http://getkickstrap.com/

テーマをダウンロードする

好きなテーマを決めたらダウンロードする。

ダウンロードするとzipになってるので解凍する。
解凍すると以下のファイルが出てくる。

bootswatch.less
variables.less

テーマを適用する

これらのlessファイルをAPP_ROOT/app/asset配下に置く。

次は、APP_ROOT/app/assets/stylesheets/bootstrap_and_overrides.css.lessに以下のimport文を追加。

@import "../bootswatch.less";
@import "../variables.less";

追加後のbootstrap_and_overrides.css.lessはこんな感じ。

@import "twitter/bootstrap/bootstrap";
@import "twitter/bootstrap/responsive";

@import "../bootswatch.less";
@import "../variables.less";

// Set the correct sprite paths
@iconSpritePath: asset-path("twitter/bootstrap/glyphicons-halflings");
@iconWhiteSpritePath: asset-path("tw
......

テーマを適用したページ


ダウンロードしたlessファイルを、なんでstylesheets配下におかないのかについては以下の記事で解説しています。
http://rainbowdevil.jp/?p=1138

関連記事

Twitter Bootstrapのテンプレート、カラーテーマなどをカスタマイズできるサービス
http://matome.naver.jp/odai/2133721441789659601

bundleしたらtherubyracerでエラー

therubyracerをインストールしようとするとエラーが起きた時のメモ。


.......
Installing therubyracer (0.11.0) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

/home/kjdev/.rvm/rubies/ruby-1.9.3-p327/bin/ruby extconf.rb
checking for main() in -lpthread... yes
checking for v8.h... no

extconf.rb failed ***

Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.

Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/home/kjdev/.rvm/rubies/ruby-1.9.3-p327/bin/ruby
--with-pthreadlib
--without-pthreadlib
--enable-debug
--disable-debug
--with-v8-dir
--without-v8-dir
--with-v8-include
--without-v8-include=${v8-dir}/include
--with-v8-lib
--without-v8-lib=${v8-dir}/lib
/home/kjdev/.rvm/gems/ruby-1.9.3-p327/gems/therubyracer-0.11.0/ext/v8/build.rb:42:in `build_with_system_libv8': unable to locate libv8. Please see output for details (RuntimeError)
from extconf.rb:22:in `

'
The Ruby Racer requires libv8 ~> 3.11.8
to be present on your system in order to compile
and link, but it could not be found.

In order to resolve this, you will either need to manually
install an appropriate libv8 and make sure that this
build process can find it. If you install it into the
standard system path, then it should just be picked up
automatically. Otherwise, you'll have to pass some extra
flags to the build process as a hint.

If you don't want to bother with all that, there is a
rubygem that will do all this for you. You can add
following line to your Gemfile:
gem 'libv8', '~> 3.11.8'

We hope that helps, and we apologize, but now we have
to push the eject button on this install.

thanks,
The Mgmt.

Gem files will remain installed in /home/kjdev/.rvm/gems/ruby-1.9.3-p327/gems/therubyracer-0.11.0 for inspection.
Results logged to /home/kjdev/.rvm/gems/ruby-1.9.3-p327/gems/therubyracer-0.11.0/ext/v8/gem_make.out
An error occurred while installing therubyracer (0.11.0), and Bundler cannot continue.
Make sure that `gem install therubyracer -v '0.11.0'` succeeds before bundling.

ログを見るとv8というjavascriptエンジンが入っていなかったかららしい。

checking for v8.h... no

gem install libv8

bundle通ったお。

参考記事

libv8を入れているのに、therubyracerがエラーになる
http://banker0507.blogspot.jp/2012/06/libv8therubyracer.html

Ruby on Railsのインストールでハマったのでメモ
http://blog.calltella.com/2012/05/ruby-on-rails.html

therubyracerでインストールエラー
http://epigonen190.blog.fc2.com/blog-entry-56.html