Railsチュートリアルはじめました
どん。
RailsいじったことはあるけどMVCの理解もあやふやだし実際アプリケーション作るってなると全然踏み出せない何から手をつけたらいいの
という経験を克服すべく実践的な開発ができそうな上記のチュートリアルをはじめてみました。
第1章
そんなわけでゼロからデプロイまでやっていきます。
このチュートリアルの素晴らしいところは網羅とか理論とかというよりそのままアプリケーション開発に応用できそうな構成をしていることで、この第1章でもrails導入したら速攻 git ホスティングサービスを利用してリモートリポジトリでコードを管理し、それをそのままHerokuにデプロイするところまで教えてくれます。
ホスティングサービスはここではセキュアなコード管理の観点から Bitbucket が推奨されていますが、自分は Github でもプライベートリポジトリがつくれるので Github とつなぎました。
詰まったところ
- Cloud9で足止めを食らう
別に必ずしもCloud9を使う必要はないのですが、家のデスクトップだけじゃなくモバイルでmacで勉強したくなることもあるかもしれないと考えてせっかくなのでCloud9を利用していきます。課金チキンでAWS個人アカウントつくったものの放置していたんですが、案の定クレカ情報を要求されたので仕方なく登録しました。
そしてこれが永遠に認証されない。
結局登録情報を確認しろ画面ではなくダッシュボードが表示されるようになるまで1週間くらいかかりました。急ぎで利用することなんかないと思いますが注意ですね。
- Herokuにデプロイできない
Herokuって何度か挑戦してるんですけどすんなりデプロイできた試しがない。ドキドキしながらgit push heroku master
したんですが案の定エラーがでました。
ec2-user:~/environment/hello_app (master) $ git push heroku master Counting objects: 90, done. Compressing objects: 100% (76/76), done. Writing objects: 100% (90/90), 20.81 KiB | 926.00 KiB/s, done. Total 90 (delta 5), reused 0 (delta 0) remote: Compressing source files... done. remote: Building source: remote: remote: ! Warning: Multiple default buildpacks reported the ability to handle this app. The first buildpack in the list below will be used. remote: Detected buildpacks: Ruby,Node.js remote: See https://devcenter.heroku.com/articles/buildpacks#buildpack-detect-order remote: -----> Ruby app detected remote: -----> Compiling Ruby/Rails remote: -----> Using Ruby version: ruby-2.4.4 remote: -----> Installing dependencies using bundler 1.15.2 remote: Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment remote: Warning: the running version of Bundler (1.15.2) is older than the version that created the lockfile (1.16.4). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`. remote: You are trying to install in deployment mode after changing remote: your Gemfile. Run `bundle install` elsewhere and add the remote: updated Gemfile.lock to version control. remote: remote: The dependencies in your gemfile changed remote: remote: You have added to the Gemfile: remote: * pg (= 0.20.0) remote: Bundler Output: Warning: the running version of Bundler (1.15.2) is older than the version that created the lockfile (1.16.4). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`. remote: You are trying to install in deployment mode after changing remote: your Gemfile. Run `bundle install` elsewhere and add the remote: updated Gemfile.lock to version control. remote: remote: The dependencies in your gemfile changed remote: remote: You have added to the Gemfile: remote: * pg (= 0.20.0) remote: remote: ! remote: ! Failed to install gems via Bundler. remote: ! remote: ! Push rejected, failed to compile Ruby app. remote: remote: ! Push failed remote: Verifying deploy... remote: remote: ! Push rejected to ******. remote: To https://git.heroku.com/******.git ! [remote rejected] master -> master (pre-receive hook declined) error: failed to push some refs to 'https://git.heroku.com/******.git'
なんで?
とりあえず上から解決していこうと buildpack を指定してみたりlockファイルを消して bundle install --without production
し直してみるも一向にデプロイできない。
結局、必要だったのは
git push origin master
でした。ええ……
よくわからないですがこの push heroku
というのはローカルではなくリモート上のoriginをみているみたいですね。Gemfileを変更して bundle install してから push するのを忘れていたのが原因でした。
まとめ
というわけで Heroku のURLから Hello world! することができました。次はscaffoldでrailsアプリを立ち上げてみるようです。この辺までは個人的に復習だったのでさくさく進めていきたいとおもいます。