LoginSignup
10
10

More than 5 years have passed since last update.

rails + heroku メモ

Last updated at Posted at 2014-02-12

herokuにdeploy

Gemfileの編集

gemfileのsqlite3の箇所を, developとproductionで変えておく(herokuはsqlite3ではなくpostgresqlなので).
Gemfileの以下の箇所を

gem 'sqlite3'

このように書き変える.

group :production do
  gem 'pg'
  gem 'therubyracer-heroku'
end
group :development, :test do
  gem 'sqlite3'
end

production.rbの編集

config.assets.compileをfalseからtrueに変更.

config/environments/production.rb
config.assets.compile = false
config/environments/production.rb
config.assets.compile = true

application.rbの編集

application.rbに以下の項目を追加.

config/application.rb
config.assets.initialize_on_precompile = false

bundleの更新

上の変更が終わったら, bundle-installをしておく. このときproductionを除くオプションを入れる.

bundle install --without production

git

applicationのrootフォルダでgit initしてgitの管理下においておく.

git init
git add .
git commit -m "commit message"

heroku側にアプリケーションを作成

herokuのアプリケーション名は全て小文字でアンダーバーも利用不可なので注意.

heroku create applicationname

gitのremoteリポジトリにherokuを追加

git remote add heroku git@heroku.com:appricationname.git

herokuにpush

git push heroku master

SSL証明書でこけたとき

cacert.pemを適当な場所からとってきて, C:\cert\cacert.pemあたりにおいて, 環境変数SSL_CERT_FILE=C:\cert\cacert.pemを設定する.

DB関連

コマンド

マイグレーションを行う.

rake db:migrate

seeds.rbに記述された内容をDBに登録する.

rake db:seed

DBの内容を削除する.

rake db:drop

heroku側の操作をする場合, herokuを先頭につける.

heroku rake db:migrate
heroku rake db:seed
heroku rake db:drop

既にあるテーブルにカラムを追加/削除する

追加/削除用のマイグレーションを作成してマイグレーションする.

rails g migration add_column_to_table name:type
rails g migration remove_column_to_table name:type
rake db:migrate

add_column_to_tableは tableモデル に column をカラム名 name, 型を typeで追加するという意味. removeは削除になる.

migrateしただけではモデル側のアクセサが設定されていないので注意. 以下のようにattr_accessibleに追加する.

attr_accessible :name
10
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
10