2012年6月12日火曜日

RailsアプリをPostgreSQLで開発してHerokuにデプロイするまでの簡単まとめ

PostgreSQLの設定や開発用ユーザーの作成、Heroku Toolbeltのインストールは完了しているものとします。

1. アプリケーション作成

$ rails new blog -d postgresql
$ cd blog

2. データベース設定

config/database.ymlの開発用DBとテスト用DBを設定

development:
  adapter: postgresql
  encoding: unicode
  database: blog_development
  pool: 5
  username: ユーザー名
  password: パスワード

.gitignoreにconfig/database.ymlを追加

# Ignore database.yml
/config/database.yml

3. データベース作成

$ rake db:create

4. データベースのマイグレーション

$ rails g scaffold post name:string title:string content:text
$ rake db:migrate

5. ルーティング設定

$ rm public/index.html

config/routes.rbを編集

  root :to => 'posts#index'

6. Herokuにデプロイ

アセットの事前コンパイル

$ rake assets:precompile

以下、デプロイ

$ git init
$ git add .
$ git commit -m 'init'
$ heroku login
$ heroku create --stack cedar
$ git push heroku master
$ heroku run rake db:migrate

動作確認

$ heroku open

動作しなければログを確認

$ heroku logs

0 件のコメント:

コメントを投稿