開発‎ > ‎フレームワーク‎ > ‎

Rails

メモ

rails dbconsole

Bundler

Rails アプリを作るにあたっては、環境に「Ruby + Rails 関連諸々」が入っている必要があるが、その後で実行する際には、「Ruby + Bundler」だけが入っていれば、"bundle install" & "bundle exec rails server" で良い(Bundler 環境下に Bundler 自身は入らない)。
初回に "bundle install --path vendor/bundle" をすると .bundle/config にパスが書き込まれるが、これを Git 管理すべきかどうかは微妙だな。

sudo 時間内に "--path" を付け忘れて "bundle install" してしまうと、断りもなくシステムワイドにインストールしやがる。sudo のタイムアウトを 0 秒にする以外で、何とかならないだろうか。

Unicorn も同様、"bundle exec unicorn --listen 0.0.0.0:3000"。デフォルトの 8080 は Tomcat に取られていた。


Apache, nginx, God, Unicorn


2.x Getting Started · capistrano/capistrano Wiki · GitHub https://github.com/capistrano/capistrano/wiki/2.x-Getting-Started
Capistranoでローカルリポジトリからソースを取得する。 - Develop with pleasure!: これだ。そうだよな、これができなきゃおかしい。

bundle exec capify .

# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   Gemfile
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       Capfile
#       config/deploy.rb

cap deploy
cap deploy:cold
cap deploy:migrate


Rails の gem までは、"private installation" に従ってユーザローカルにインスコ、もしくは distro のパッケージ管理に従ってインストール。スケルトン作成以降は、Bundler 頼みで。

gem install rails

他環境でのバージョン固定は?

アプリケーションスケルトン

rails コマンドと、アプリケーションへの rake コマンドとが紛らわしい。OOP 的に言うと、前者がクラスメソッドと継承されたメソッドにあたり、後者は派生クラスで実装を持っているメソッド、という感じだ。

つまり、図で書くとこう:

rails と rake


$ rails new appname

アプリ名は snake case が良
かろ
うな。

Ac
tiveR
ecord

$ rails generate model user user_id:text user_name:text

$ rake db:migrate

$ rake db:fixtures:load FIXTURES=users

$ rails dbconsole

$ rails generate scaffold book title:string author:string

$ rake db:fixtures:load FIXTURES=books

RSpec


Comments