LoginSignup
4
4

More than 5 years have passed since last update.

はじめてのrailsをHerokuで動かすまでのまとめ

Last updated at Posted at 2015-12-04

はじめてのruby on railsだったので自分のためにまとめてみました。

とりあえずローカルで動くものを作る
(ドットインストールは未読、あとで読む)
http://www.atmarkit.co.jp/ait/articles/1402/27/news042.html
http://www.atmarkit.co.jp/ait/articles/1402/28/news047.html
http://www.atmarkit.co.jp/ait/articles/1403/28/news035.html
http://dotinstall.com/lessons/basic_rails_v2

あたらしいgemをインストールして使ってみる
(flickrが面白そうだったので選んでみた)
http://easyramble.com/flickr-api-with-ruby-flickraw.html

ローカルのgitリポジトリでソース管理
http://www.backlog.jp/git-guide/intro/intro1_1.html

ここまで約2時間。速い速い。

Herokuを使う準備
http://kuranuki.sonicgarden.jp/2009/05/rubypaasherokurails.html
http://morizyun.github.io/blog/beginner-rails-heroku-tutorial/
http://gam0022.net/blog/2013/09/17/run-rails4-on-heroku/
 (Rails4のアプリをHerokuで動かす)
http://qiita.com/satton_maroyaka/items/2631db410764784e305c
 (herokuのpostgreSQLのDBにローカル環境からSQLを実行する。)

これも簡単だった!合計3時間。まじ神。すげー!

※見返してコケたことがあったので4点追記。

1)Gemfileとconfig/database.ymlを書き換える

Gemfile の gem 'sqlite3' を下記に


group :development, :test do
  gem 'sqlite3'
end
group :production do
  gem 'pg'
  gem 'rails_12factor'
end


config/database.yml の production の設定を下記に

production:
  adapter: postgresql
  encoding: unicode
  database:
  pool: 5
  username:
  password:

2)postgresqlが入っていなければ入れる

gem install pg

ここらへんで困ったときはここで解決しました(ありがとう)
http://qiita.com/youcune/items/

あと、一生懸命英語読むことw

3).gitignoreも変える

# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-journal

4)上記をやったら、あとはコミットを忘れないようにするw

できたもの。
https://shizuoka-artsaward.herokuapp.com/top/index/
↑しずおかアプリコンテスト用に作りましたw
https://secure-wildwood-3289.herokuapp.com/index/

よく使うコマンド
参照:http://railsdoc.com/rails (古いのもあるから注意する)

起動
$ rails server

gemファイル編集後のbundle
$ bundle install
$ bundle install --widthout production

モデルを作る
$ bundle exec rails generate model user name:string department:string
$ bundle exec rake db:migrate

コンソールに入る
$ bundle exec rails console

DBコンソールに入る
$ rails dbconsole

config/routes.rb編集後
$ rake routes

gitにコミットする
$ git add .
$ git commit -m "modify hogehoge"

herokuにソースをpushする
$ git push heroku master

herokuにDBの変更を反映する
$ heroku run bundle exec rake db:migrate

herokuページをひらく
$ heroku open

herokuのログを確認する
$ heroku logs -t

herokuのデータベース操作
$ heroku pg:psql
*Type \q and then press ENTER to quit psql.
4
4
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
4
4