見出し画像

railsチュートリアル挑戦記 第1章 ゼロからデプロイまで

railsチュートリアルをやりながらメモしたことをそのまま記述しています。

・1 1 はじめに

Airbnb, Basecamp, Disney, GitHub, Hulu, Kickstarter, Shopify, Twitter, Yellow Pagesなど多くの企業でrailsが採用されてい
ENTP, thoughtbot, Pivotal Labs, Hashrocket, HappyFunCorpはrailsを専門的に扱う
多くの人に使われている理由はオープンソースで制約の少ないMITライセンスで公開されているため。
railsは最新のwebテクノロジーやフレームワーク設計に素早く適応する

・1 1 1 前提知識

チュートリアルでは
ruby,minitest,html,css,javascript,sql
が使われる

演習1
Ruby on Railsで使うRuby gemはどのWebサイトにありますか?
→https://rubygems.org/

演習2
現時点でのRailsの最新バージョンはいくつですか?
→https://rubyonrails.org/
→6.0.2.1

演習3
Ruby on Railsはこれまでに何回ダウンロードされたでしょうか?
→しらん。まあ必要ないやろ

・1 1 2 この本における取り決め

コマンドラインで使うディレクトリの区切りは/
rails newで作成したディレクトリより上は省略して記述してる

railsで困ったら下のサイトとか参考になるかも
https://railstutorial.jp/help

テストが失敗するコードは赤文字
テストが成功するコードは緑文字

重要な部分は蛍光ペンで塗りつぶした

長いコードは


で省略してる

・1 2 さっそく動かす

開発環境構築ってムズいよねっていうお話
方法1はLearnEnoughに沿って学習すること
https://www.learnenough.com/

方法2はクラウド統合開発環境(クラウドIDE)を使う

・1 2 1 開発環境

環境構築の複雑さを避けるためにAWS Cloud9を使うよ
AWS Cloud9はRuby,RubyGems,Gitが組み込まれてるよ
railsやherokuはないけどその辺の説明は1.2.2章で説明するよ

もしローカルで環境構築したいんだったら以下のサイトオススメよ
https://railsgirls.jp/install

ちなAWS Cloud9にはテキストエディタ、ファイルブラウザ、コマンドラインターミナルが入ってるやで

さっそくクラウドIDEを利用しよう
①AWSのアカウントが必要だよ。もし持ってたらAWSコンソールで検索ボックスからCloud9と入力すればCloud9の開発環境を作成するためのページに行けるよ
②AWSアカウントは以下のURLで作れるよ
https://portal.aws.amazon.com/billing/signup#/start

そのときの備忘録を以下のnoteにまとめました
開発環境構築備忘録 AWS編(1日目)
https://note.com/el93019205/n/na33803e8452b
開発環境構築備忘録 AWS編(2日目)
https://note.com/el93019205/n/n72a6472fe04d

※ここでハマる人は多い!クレジットカードの認証でつまずく。カード会社にAWS使いたいから認証外してくれと伝える必要がある

③AWSアカウント作れたらcloud9の設定方法をするよ

そのときの備忘録を以下のnoteにまとめました
開発環境構築備忘録 AWS cloud9編
https://note.com/el93019205/n/nf4489a52e788

ちなrubyの世界ではインデントに2つのスペースを使うのが常識らしい

・1 2 2 Railsをインストールする

AWSのcloud9ではrailsはそのまま使えないのでrailsをインストールする
そのときの備忘録を以下のnoteにまとめました
開発環境構築備忘録 AWS cloud9 rails編
https://note.com/el93019205/n/nf2f280de0497

・1 3 最初のアプリケーション

ローカルでやる場合はenvironmentディレクトリ作ってやるけど、
今回cloud9でデフォルトがenvironmentなので特にディレクトリの作成は必要なし

シェルというのは実際に動くコマンドやプログラムにかぶさってるインターフェース

主要なUNIXコマンド
-------------------
ディレクトリ内容の表示	ls
ディレクトリの作成		mkdir ディレクトリ名
ディレクトリの移動		cd ディレクトリ名
上のディレクトリに移動	cd ..
ホームディレクトリに移動	cd
environmentに移動	cd ~/environment
ファイルの移動		mv 移動元 移動先
ファイルのリネーム		mv 現在の名前 変更後の名前
ファイルのコピー		cp コピー元 コピー先
ファイルの削除		rm ファイル名
空のディレクトリの削除	rmdir ディレクトリ名
空でないディレクトリの削除	rm -rf ディレクトリ名
ファイルの内容の結合と表示	cat ファイル名

railsアプリケーションを、バージョン番号つきで作成する
rails _5.1.6_ new hello_app

     create  
     create  README.md
     create  Rakefile
     create  config.ru
     create  .gitignore
     create  Gemfile
        run  git init from "."
Initialized empty Git repository in /home/ec2-user/environment/hello_app/.git/
     create  app
     create  app/assets/config/manifest.js
     create  app/assets/javascripts/application.js
     create  app/assets/javascripts/cable.js
     create  app/assets/stylesheets/application.css
     create  app/channels/application_cable/channel.rb
     create  app/channels/application_cable/connection.rb
     create  app/controllers/application_controller.rb
     create  app/helpers/application_helper.rb
     create  app/jobs/application_job.rb
     create  app/mailers/application_mailer.rb
     create  app/models/application_record.rb
     create  app/views/layouts/application.html.erb
     create  app/views/layouts/mailer.html.erb
     create  app/views/layouts/mailer.text.erb
     create  app/assets/images/.keep
     create  app/assets/javascripts/channels
     create  app/assets/javascripts/channels/.keep
     create  app/controllers/concerns/.keep
     create  app/models/concerns/.keep
     create  bin
     create  bin/bundle
     create  bin/rails
     create  bin/rake
     create  bin/setup
     create  bin/update
     create  bin/yarn
     create  config
     create  config/routes.rb
     create  config/application.rb
     create  config/environment.rb
     create  config/secrets.yml
     create  config/cable.yml
     create  config/puma.rb
     create  config/spring.rb
     create  config/environments
     create  config/environments/development.rb
     create  config/environments/production.rb
     create  config/environments/test.rb
     create  config/initializers
     create  config/initializers/application_controller_renderer.rb
     create  config/initializers/assets.rb
     create  config/initializers/backtrace_silencers.rb
     create  config/initializers/cookies_serializer.rb
     create  config/initializers/cors.rb
     create  config/initializers/filter_parameter_logging.rb
     create  config/initializers/inflections.rb
     create  config/initializers/mime_types.rb
     create  config/initializers/new_framework_defaults_5_1.rb
     create  config/initializers/wrap_parameters.rb
     create  config/locales
     create  config/locales/en.yml
     create  config/boot.rb
     create  config/database.yml
     create  db
     create  db/seeds.rb
     create  lib
     create  lib/tasks
     create  lib/tasks/.keep
     create  lib/assets
     create  lib/assets/.keep
     create  log
     create  log/.keep
     create  public
     create  public/404.html
     create  public/422.html
     create  public/500.html
     create  public/apple-touch-icon-precomposed.png
     create  public/apple-touch-icon.png
     create  public/favicon.ico
     create  public/robots.txt
     create  test/fixtures
     create  test/fixtures/.keep
     create  test/fixtures/files
     create  test/fixtures/files/.keep
     create  test/controllers
     create  test/controllers/.keep
     create  test/mailers
     create  test/mailers/.keep
     create  test/models
     create  test/models/.keep
     create  test/helpers
     create  test/helpers/.keep
     create  test/integration
     create  test/integration/.keep
     create  test/test_helper.rb
     create  test/system
     create  test/system/.keep
     create  test/application_system_test_case.rb
     create  tmp
     create  tmp/.keep
     create  tmp/cache
     create  tmp/cache/assets
     create  vendor
     create  vendor/.keep
     create  package.json
     remove  config/initializers/cors.rb
     remove  config/initializers/new_framework_defaults_5_1.rb
        run  bundle install
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Fetching gem metadata from https://rubygems.org/............
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies....
Fetching rake 13.0.1
Installing rake 13.0.1
Using concurrent-ruby 1.1.5
Fetching i18n 1.7.0
Installing i18n 1.7.0
Fetching minitest 5.13.0
Installing minitest 5.13.0
Using thread_safe 0.3.6
Fetching tzinfo 1.2.6
Installing tzinfo 1.2.6
Fetching activesupport 5.1.7
Installing activesupport 5.1.7
Using builder 3.2.4
Using erubi 1.9.0
Using mini_portile2 2.4.0
Using nokogiri 1.10.7
Using rails-dom-testing 2.0.3
Using crass 1.0.5
Using loofah 2.4.0
Using rails-html-sanitizer 1.3.0
Fetching actionview 5.1.7
Installing actionview 5.1.7
Using rack 2.0.8
Fetching rack-test 1.1.0
Installing rack-test 1.1.0
Fetching actionpack 5.1.7
Installing actionpack 5.1.7
Using nio4r 2.5.2
Using websocket-extensions 0.1.4
Using websocket-driver 0.6.5
Fetching actioncable 5.1.7
Installing actioncable 5.1.7
Using globalid 0.4.2
Fetching activejob 5.1.7
Installing activejob 5.1.7
Using mini_mime 1.0.2
Using mail 2.7.1
Fetching actionmailer 5.1.7
Installing actionmailer 5.1.7
Fetching activemodel 5.1.7
Installing activemodel 5.1.7
Using arel 8.0.0
Fetching activerecord 5.1.7
Installing activerecord 5.1.7
Fetching public_suffix 4.0.1
Installing public_suffix 4.0.1
Fetching addressable 2.7.0
Installing addressable 2.7.0
Fetching bindex 0.8.1
Installing bindex 0.8.1 with native extensions
Using bundler 1.17.3
Fetching byebug 11.0.1
Installing byebug 11.0.1 with native extensions
Fetching xpath 3.2.0
Installing xpath 3.2.0
Fetching capybara 2.18.0
Installing capybara 2.18.0
Fetching childprocess 3.0.0
Installing childprocess 3.0.0
Fetching coffee-script-source 1.12.2
Installing coffee-script-source 1.12.2
Fetching execjs 2.7.0
Installing execjs 2.7.0
Fetching coffee-script 2.4.1
Installing coffee-script 2.4.1
Using method_source 0.9.2
Using thor 1.0.1
Fetching railties 5.1.7
Installing railties 5.1.7
Fetching coffee-rails 4.2.2
Installing coffee-rails 4.2.2
Fetching ffi 1.11.3
Installing ffi 1.11.3 with native extensions
Fetching jbuilder 2.9.1
Installing jbuilder 2.9.1
Fetching rb-fsevent 0.10.3
Installing rb-fsevent 0.10.3
Fetching rb-inotify 0.10.1
Installing rb-inotify 0.10.1
Fetching ruby_dep 1.5.0
Installing ruby_dep 1.5.0
Fetching listen 3.1.5
Installing listen 3.1.5
Fetching puma 3.12.2
Installing puma 3.12.2 with native extensions
Fetching sprockets 3.7.2
Installing sprockets 3.7.2
Using sprockets-rails 3.2.1
Fetching rails 5.1.7
Installing rails 5.1.7
Fetching rubyzip 2.0.0
Installing rubyzip 2.0.0
Fetching sass-listen 4.0.0
Installing sass-listen 4.0.0
Fetching sass 3.7.4
Installing sass 3.7.4
Fetching tilt 2.0.10
Installing tilt 2.0.10
Fetching sass-rails 5.0.7
Installing sass-rails 5.0.7
Fetching selenium-webdriver 3.142.6
Installing selenium-webdriver 3.142.6
Fetching spring 2.1.0
Installing spring 2.1.0
Fetching spring-watcher-listen 2.0.1
Installing spring-watcher-listen 2.0.1
Fetching sqlite3 1.4.2
Installing sqlite3 1.4.2 with native extensions
Fetching turbolinks-source 5.2.0
Installing turbolinks-source 5.2.0
Fetching turbolinks 5.2.1
Installing turbolinks 5.2.1
Fetching uglifier 4.2.0
Installing uglifier 4.2.0
Fetching web-console 3.7.0
Installing web-console 3.7.0
Bundle complete! 16 Gemfile dependencies, 69 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
Post-install message from i18n:
HEADS UP! i18n 1.1 changed fallbacks to exclude default locale.
But that may break your application.
Please check your Rails app for 'config.i18n.fallbacks = true'.
If you're using I18n (>= 1.1.0) and Rails (< 5.2.2), this should be
'config.i18n.fallbacks = [I18n.default_locale]'.
If not, fallbacks will be broken in your app by I18n 1.1.x.
For more info see:
https://github.com/svenfuchs/i18n/releases/tag/v1.1.0
Post-install message from sass:
Ruby Sass has reached end-of-life and should no longer be used.
* If you use Sass as a command-line tool, we recommend using Dart Sass, the new
 primary implementation: https://sass-lang.com/install
* If you use Sass as a plug-in for a Ruby web framework, we recommend using the
 sassc gem: https://github.com/sass/sassc-ruby#readme
* For more details, please refer to the Sass blog:
 https://sass-lang.com/blog/posts/7828841
        run  bundle exec spring binstub --all
* bin/rake: Spring inserted
* bin/rails: Spring insertedrails-tutorialディレクトリの直下に作成されることを確認

hello_appの中身もProgateと同じようにたくさんのファイルが作られていることを確認!
どうやらenvironment(環境という意味)が、rails-tutorialディレクトリを指しているらしい

ちなみにcloud9だとrails newのあとに勝手にbundle installを実行してくれるらしい

railsのフォルダ構造
-------------------
app/			モデル、ビュー、コントローラ、ヘルパーなどを含む主要なアプリケーションコード
app/assets		アプリケーションで使うCSS、JavaScriptファイル、画像などのアセット
bin/			バイナリ実行可能ファイル
config/			アプリケーションの設定
db/			データベース関連のファイル
doc/			マニュアルなど、アプリケーションのドキュメント
lib/			ライブラリモジュール
lib/assets		ライブラリで使うCSS 、JavaScriptファイル、画像などのアセット
log/			アプリケーションのログファイル
public/			エラーページなど、一般(Webブラウザなど)に直接公開するデータ
bin/rails		コード生成、コンソールの起動、ローカルのWebサーバの立ち上げなどで使うRailsスクリプト
test/			アプリケーションのテスト
tmp/			一時ファイル
vendor/			サードパーティのプラグインやgemなど
vendor/assets	        サードパーティのプラグインやgemで使うCSS、JavaScriptファイル、画像などのアセット
README.md		アプリケーションの簡単な説明
Rakefile		rakeコマンドで使えるタスク
Gemfile			このアプリケーションに必要なGemの定義ファイル
Gemfile.lock	        アプリケーションで使われるgemのバージョンを確認するためのリスト
config.ru		Rackミドルウェア用の設定ファイル
.gitignore		Gitに取り込みたくないファイルを指定するためのパターン

・1 3 1 Bundler

アプリケーションに必要なgemをインストールするために、bundle installを実行する
ただし、cloud9ではすでに実行済み
Gemfileをダブルクリックして中身を確認してみる

このとき、cloud9でなんか表示おかしいなーと思ったら左のナビゲーターの歯車をポチしてRefresh File Treeをポチ

Gemfileには、各種使うやつのバージョンとかこと細かに書かれてる

以下のようにすると1.3.0以上であれば最新バージョンのgemがインストール
gem 'uglifier', '>= 1.3.0'

以下のようにすると4.0.0より大きく4.1より小さい場合インストール
gem 'coffee-rails', '~> 4.0.0'

各バージョンに少しでもずれがあるとエラーが多発する(筆者経験談)
だからrailsチュートリアルではガッチリ固定

railsチュートリアル用のバージョンがっちり固定したバージョン
-------------------
source 'https://rubygems.org'
gem 'rails',        '5.1.6'
gem 'puma',         '3.9.1'
gem 'sass-rails',   '5.0.6'
gem 'uglifier',     '3.2.0'
gem 'coffee-rails', '4.2.2'
gem 'jquery-rails', '4.3.1'
gem 'turbolinks',   '5.0.1'
gem 'jbuilder',     '2.6.4'
group :development, :test do
 gem 'sqlite3',      '1.3.13'
 gem 'byebug', '9.0.6', platform: :mri
end
group :development do
 gem 'web-console',           '3.5.1'
 gem 'listen',                '3.1.5'
 gem 'spring',                '2.0.2'
 gem 'spring-watcher-listen', '2.0.1'
end
# Windows環境ではtzinfo-dataというgemを含める必要があります
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

書き換えたら以下のコマンド
cd hello_app
bundle install


ログ
-------------------
ec2-user:~/environment/hello_app (master) $ bundle install
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Fetching gem metadata from https://rubygems.org/............
Fetching gem metadata from https://rubygems.org/.
You have requested:
 spring = 2.0.2
The bundle currently has spring locked at 2.1.0.
Try running `bundle update spring`
If you are updating multiple gems in your Gemfile at once,
try passing them all to `bundle update`
ec2-user:~/environment/hello_app (master) $ 

失敗してるな・・・
bundle updateを先にしろって言われてるな
じゃあ
bundle update

ログ
-------------------
ec2-user:~/environment/hello_app (master) $ bundle update
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Fetching gem metadata from https://rubygems.org/............
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies....
Using rake 13.0.1
Using concurrent-ruby 1.1.5
Using i18n 1.7.0
Using minitest 5.13.0
Using thread_safe 0.3.6
Using tzinfo 1.2.6
Using activesupport 5.1.6 (was 5.1.7)
Using builder 3.2.4
Using erubi 1.9.0
Using mini_portile2 2.4.0
Using nokogiri 1.10.7
Using rails-dom-testing 2.0.3
Using crass 1.0.5
Using loofah 2.4.0
Using rails-html-sanitizer 1.3.0
Using actionview 5.1.6 (was 5.1.7)
Using rack 2.0.8
Using rack-test 1.1.0
Using actionpack 5.1.6 (was 5.1.7)
Using nio4r 2.5.2
Using websocket-extensions 0.1.4
Using websocket-driver 0.6.5
Using actioncable 5.1.6 (was 5.1.7)
Using globalid 0.4.2
Using activejob 5.1.6 (was 5.1.7)
Using mini_mime 1.0.2
Using mail 2.7.1
Using actionmailer 5.1.6 (was 5.1.7)
Using activemodel 5.1.6 (was 5.1.7)
Using arel 8.0.0
Using activerecord 5.1.6 (was 5.1.7)
Using bindex 0.8.1
Using bundler 1.17.3
Fetching byebug 9.0.6 (was 11.0.1)
Installing byebug 9.0.6 (was 11.0.1) with native extensions
Using coffee-script-source 1.12.2
Using execjs 2.7.0
Using coffee-script 2.4.1
Using method_source 0.9.2
Using thor 1.0.1
Using railties 5.1.6 (was 5.1.7)
Using coffee-rails 4.2.2
Using ffi 1.11.3
Fetching multi_json 1.14.1
Installing multi_json 1.14.1
Fetching jbuilder 2.6.4 (was 2.9.1)
Installing jbuilder 2.6.4 (was 2.9.1)
Fetching jquery-rails 4.3.1
Installing jquery-rails 4.3.1
Using rb-fsevent 0.10.3
Using rb-inotify 0.10.1
Using ruby_dep 1.5.0
Using listen 3.1.5
Fetching puma 3.9.1 (was 3.12.2)
Installing puma 3.9.1 (was 3.12.2) with native extensions
Using sprockets 3.7.2
Using sprockets-rails 3.2.1
Using rails 5.1.6 (was 5.1.7)
Using sass-listen 4.0.0
Using sass 3.7.4
Using tilt 2.0.10
Fetching sass-rails 5.0.6 (was 5.0.7)
Installing sass-rails 5.0.6 (was 5.0.7)
Fetching spring 2.0.2 (was 2.1.0)
Installing spring 2.0.2 (was 2.1.0)
Using spring-watcher-listen 2.0.1
Fetching sqlite3 1.3.13 (was 1.4.2)
Installing sqlite3 1.3.13 (was 1.4.2) with native extensions
Using turbolinks-source 5.2.0
Fetching turbolinks 5.0.1 (was 5.2.1)
Installing turbolinks 5.0.1 (was 5.2.1)
Fetching uglifier 3.2.0 (was 4.2.0)
Installing uglifier 3.2.0 (was 4.2.0)
Fetching web-console 3.5.1 (was 3.7.0)
Installing web-console 3.5.1 (was 3.7.0)
Bundle updated!
ec2-user:~/environment/hello_app (master) $ 

そして
bundle install


ログ
-------------------
ec2-user:~/environment/hello_app (master) $ bundle install
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Using rake 13.0.1
Using concurrent-ruby 1.1.5
Using i18n 1.7.0
Using minitest 5.13.0
Using thread_safe 0.3.6
Using tzinfo 1.2.6
Using activesupport 5.1.6
Using builder 3.2.4
Using erubi 1.9.0
Using mini_portile2 2.4.0
Using nokogiri 1.10.7
Using rails-dom-testing 2.0.3
Using crass 1.0.5
Using loofah 2.4.0
Using rails-html-sanitizer 1.3.0
Using actionview 5.1.6
Using rack 2.0.8
Using rack-test 1.1.0
Using actionpack 5.1.6
Using nio4r 2.5.2
Using websocket-extensions 0.1.4
Using websocket-driver 0.6.5
Using actioncable 5.1.6
Using globalid 0.4.2
Using activejob 5.1.6
Using mini_mime 1.0.2
Using mail 2.7.1
Using actionmailer 5.1.6
Using activemodel 5.1.6
Using arel 8.0.0
Using activerecord 5.1.6
Using bindex 0.8.1
Using bundler 1.17.3
Using byebug 9.0.6
Using coffee-script-source 1.12.2
Using execjs 2.7.0
Using coffee-script 2.4.1
Using method_source 0.9.2
Using thor 1.0.1
Using railties 5.1.6
Using coffee-rails 4.2.2
Using ffi 1.11.3
Using multi_json 1.14.1
Using jbuilder 2.6.4
Using jquery-rails 4.3.1
Using rb-fsevent 0.10.3
Using rb-inotify 0.10.1
Using ruby_dep 1.5.0
Using listen 3.1.5
Using puma 3.9.1
Using sprockets 3.7.2
Using sprockets-rails 3.2.1
Using rails 5.1.6
Using sass-listen 4.0.0
Using sass 3.7.4
Using tilt 2.0.10
Using sass-rails 5.0.6
Using spring 2.0.2
Using spring-watcher-listen 2.0.1
Using sqlite3 1.3.13
Using turbolinks-source 5.2.0
Using turbolinks 5.0.1
Using uglifier 3.2.0
Using web-console 3.5.1
Bundle complete! 15 Gemfile dependencies, 64 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
ec2-user:~/environment/hello_app (master) $ 

・1 3 2 rails server

rails serverを実行する
このとき、ちゃんとhello_appの下で実行する

ログ
-------------------
ec2-user:~/environment/hello_app (master) $ rails server
=> Booting Puma
=> Rails 5.1.6 application starting in development 
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.9.1 (ruby 2.6.3-p62), codename: Private Caller
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:8080
Use Ctrl-C to stop

JavaScriptランタイムがインストールされてないってエラーが出てたら
https://github.com/sstephenson/execjs
からJavaScriptを入手してねって言われる(でもどうやってやるんだろう・・・?)

今回はエラーが出なかったのでそのまま次へ・・・残念!


cloud9のサーバー用のターミナルと、コマンド用のターミナルは分けておくと作業しやすい
ターミナルの+ボタンの上から2つ目のNew Terminalを選択・・・だけどちょっとまった。
ショートカットを覚えておいたほうがいいな。
Alt+tでターミナルが開ける→ひらけた!
ターミナルを閉じるショートカットを探したけどそれはなかった。
サーバーを閉じるときのショートカットはサーバーを立てたターミナルでCtrl+c

ブラウザでrailsアプリケーションを表示するには、
ローカルサーバーの場合:http://localhost:3000/
cloud9の場合:Preview→Preview Running Application→右下に出た画面の拡縮みたいなボタン(それっぽいの2つあるけど右下のやつ)をクリック

※注意 cloud9でrailsチュートリアルの文章の通りにやっても表示されないので、上の方法で

ここで演習きたので演習やってみる

演習1
デフォルトのRailsページに表示されているものと比べて、今の自分のコンピュータにあるRubyのバージョンはいくつになっていますか? コマンドラインでruby -vを実行することで簡単に確認できます。
→ruby -v
ローカル環境:ruby 2.6.5p114 (2019-10-01 revision 67812) [x64-mingw32]
cloud9 :ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux]

演習2
同様にして、Railsのバージョンも調べてみましょう。調べたバージョンはリスト 1.1でインストールしたバージョンと一致しているでしょうか?
→rails -v
ローカル環境:Rails 6.0.2.1
cloud9 :Rails 5.1.7

・1 3 3 Model-View-Controller (MVC)

MVCの概要

MVCアーキテクチャ

・1 3 4 Hello, world!

以下のコマンドは、現在あるコントローラを確認できる魔法のコマンド
ls app/controllers/*_controller.rb
実行してみると・・・?
app/controllers/application_controller.rb
と出る

hello_app/app/controllers/application_controllerのクラスの中に以下のアクションを書いてみる
def hello
render html: "hello, world!"
end

controllerに定義したメソッドはアクションと呼ぶ

次はルーティングを弄る
ルーティングはMVCどれにも当てはまらないので別ディレクトリと覚えるといい
ちなみにconfig/routes.rbにルーティングを書ける
root 'application#hello'

コントローラとルーティングを書き換えたら更新
Hello World!と表示された!感動!

ここで演習
「文字列の表示を変えてみよう」
「非ASCII文字も表示できるから表示してみよう」
「2つ目のアクションを作って、rootを2つ目のアクションにしよう」
演習はやるまでもなく、簡単すぎてしょーもないから飛ばした

・1 4 Gitによるバージョン管理

特に重要な情報はなし

・1 4 1 インストールとセットアップ

手順にはないけどgitのバージョンを確認してみた
git --version
git version 2.14.5って出た

gitにユーザー名とメールアドレスを設定する必要があるので以下のコマンドで設定する
git config --global user.name "ナイショ"
git config --global user.email ナイショ@ナイショ.com
・・・音沙汰なしで終わるけど気にしない

今後リポジトリ上で晒されるらしいから注意


リポジトリを作成するためにgit initをhello_appディレクトリでやる

ログ
-------------------
ec2-user:~ $ cd environment
ec2-user:~/environment $ cd hello_app
ec2-user:~/environment/hello_app (master) $ git init
Reinitialized existing Git repository in /home/ec2-user/environment/hello_app/.git/
ec2-user:~/environment/hello_app (master) $ 

ん?テキストと違うログだな・・・
ただこれ、エラーじゃなくてもう一回初期化したやでって言われてる
初めてやったつもりだけどなまあいいか

続いて、gitのACPのAをやる
git add -A
※-Aオプションは全てのファイルを指す
ログは出なかったな

念のためgit statusでなにがaddされたのかを見る

ログ
-------------------
ec2-user:~/environment/hello_app (master) $ git status
On branch master
No commits yet
Changes to be committed:
 (use "git rm --cached <file>..." to unstage)
       new file:   .gitignore
       new file:   Gemfile
       new file:   Gemfile.lock
       new file:   README.md
       new file:   Rakefile
       new file:   app/assets/config/manifest.js
       new file:   app/assets/images/.keep
       new file:   app/assets/javascripts/application.js
       new file:   app/assets/javascripts/cable.js
       new file:   app/assets/javascripts/channels/.keep
       new file:   app/assets/stylesheets/application.css
       new file:   app/channels/application_cable/channel.rb
       new file:   app/channels/application_cable/connection.rb
       new file:   app/controllers/application_controller.rb
       new file:   app/controllers/concerns/.keep
       new file:   app/helpers/application_helper.rb
       new file:   app/jobs/application_job.rb
       new file:   app/mailers/application_mailer.rb
       new file:   app/models/application_record.rb
       new file:   app/models/concerns/.keep
       new file:   app/views/layouts/application.html.erb
       new file:   app/views/layouts/mailer.html.erb
       new file:   app/views/layouts/mailer.text.erb
       new file:   bin/bundle
       new file:   bin/rails
       new file:   bin/rake
       new file:   bin/setup
       new file:   bin/spring
       new file:   bin/update
       new file:   bin/yarn
       new file:   config.ru
       new file:   config/application.rb
       new file:   config/boot.rb
       new file:   config/cable.yml
       new file:   config/database.yml
       new file:   config/environment.rb
       new file:   config/environments/development.rb
       new file:   config/environments/production.rb
       new file:   config/environments/test.rb
       new file:   config/initializers/application_controller_renderer.rb
       new file:   config/initializers/assets.rb
       new file:   config/initializers/backtrace_silencers.rb
       new file:   config/initializers/cookies_serializer.rb
       new file:   config/initializers/filter_parameter_logging.rb
       new file:   config/initializers/inflections.rb
       new file:   config/initializers/mime_types.rb
       new file:   config/initializers/wrap_parameters.rb
       new file:   config/locales/en.yml
       new file:   config/puma.rb
       new file:   config/routes.rb
       new file:   config/secrets.yml
       new file:   config/spring.rb
       new file:   db/seeds.rb
       new file:   lib/assets/.keep
       new file:   lib/tasks/.keep
       new file:   log/.keep
       new file:   package.json
       new file:   public/404.html
       new file:   public/422.html
       new file:   public/500.html
       new file:   public/apple-touch-icon-precomposed.png
       new file:   public/apple-touch-icon.png
       new file:   public/favicon.ico
       new file:   public/robots.txt
       new file:   test/application_system_test_case.rb
       new file:   test/controllers/.keep
       new file:   test/fixtures/.keep
       new file:   test/fixtures/files/.keep
       new file:   test/helpers/.keep
       new file:   test/integration/.keep
       new file:   test/mailers/.keep
       new file:   test/models/.keep
       new file:   test/system/.keep
       new file:   test/test_helper.rb
       new file:   tmp/.keep
       new file:   vendor/.keep
ec2-user:~/environment/hello_app (master) $ 

なるほど(なるほど)

続いて

※次のコマンドで失敗してます

git commit -M "Initialize repository"
でコメントをつけてく


ログ
-------------------
ec2-user:~/environment/hello_app (master) $ git commit -M "Initialize repository"
error: unknown switch `M'
usage: git commit [<options>] [--] <pathspec>...
   -q, --quiet           suppress summary after successful commit
   -v, --verbose         show diff in commit message template
Commit message options
   -F, --file <file>     read message from file
   --author <author>     override author for commit
   --date <date>         override date for commit
   -m, --message <message>
                         commit message
   -c, --reedit-message <commit>
                         reuse and edit message from specified commit
   -C, --reuse-message <commit>
                         reuse message from specified commit
   --fixup <commit>      use autosquash formatted message to fixup specified commit
   --squash <commit>     use autosquash formatted message to squash specified commit
   --reset-author        the commit is authored by me now (used with -C/-c/--amend)
   -s, --signoff         add Signed-off-by:
   -t, --template <file>
                         use specified template file
   -e, --edit            force edit of commit
   --cleanup <default>   how to strip spaces and #comments from message
   --status              include status in commit message template
   -S, --gpg-sign[=<key-id>]
                         GPG sign commit
Commit contents options
   -a, --all             commit all changed files
   -i, --include         add specified files to index for commit
   --interactive         interactively add files
   -p, --patch           interactively add changes
   -o, --only            commit only specified files
   -n, --no-verify       bypass pre-commit and commit-msg hooks
   --dry-run             show what would be committed
   --short               show status concisely
   --branch              show branch information
   --porcelain           machine-readable output
   --long                show status in long format (default)
   -z, --null            terminate entries with NUL
   --amend               amend previous commit
   --no-post-rewrite     bypass post-rewrite hook
   -u, --untracked-files[=<mode>]
                         show untracked files, optional modes: all, normal, no. (Default: all)
ec2-user:~/environment/hello_app (master) $ 

-Mじゃなくて-mだった
×git commit -M "Initialize repository"
〇git commit -m "Initialize repository"
気を取り直してもう一度!


ログ
-------------------
ec2-user:~/environment/hello_app (master) $ git commit -m "Initialize repository"
[master (root-commit) e7ab376] Initialize repository
76 files changed, 1157 insertions(+)
create mode 100644 .gitignore
create mode 100644 Gemfile
create mode 100644 Gemfile.lock
create mode 100644 README.md
create mode 100644 Rakefile
create mode 100644 app/assets/config/manifest.js
create mode 100644 app/assets/images/.keep
create mode 100644 app/assets/javascripts/application.js
create mode 100644 app/assets/javascripts/cable.js
create mode 100644 app/assets/javascripts/channels/.keep
create mode 100644 app/assets/stylesheets/application.css
create mode 100644 app/channels/application_cable/channel.rb
create mode 100644 app/channels/application_cable/connection.rb
create mode 100644 app/controllers/application_controller.rb
create mode 100644 app/controllers/concerns/.keep
create mode 100644 app/helpers/application_helper.rb
create mode 100644 app/jobs/application_job.rb
create mode 100644 app/mailers/application_mailer.rb
create mode 100644 app/models/application_record.rb
create mode 100644 app/models/concerns/.keep
create mode 100644 app/views/layouts/application.html.erb
create mode 100644 app/views/layouts/mailer.html.erb
create mode 100644 app/views/layouts/mailer.text.erb
create mode 100755 bin/bundle
create mode 100755 bin/rails
create mode 100755 bin/rake
create mode 100755 bin/setup
create mode 100755 bin/spring
create mode 100755 bin/update
create mode 100755 bin/yarn
create mode 100644 config.ru
create mode 100644 config/application.rb
create mode 100644 config/boot.rb
create mode 100644 config/cable.yml
create mode 100644 config/database.yml
create mode 100644 config/environment.rb
create mode 100644 config/environments/development.rb
create mode 100644 config/environments/production.rb
create mode 100644 config/environments/test.rb
create mode 100644 config/initializers/application_controller_renderer.rb
create mode 100644 config/initializers/assets.rb
create mode 100644 config/initializers/backtrace_silencers.rb
create mode 100644 config/initializers/cookies_serializer.rb
create mode 100644 config/initializers/filter_parameter_logging.rb
create mode 100644 config/initializers/inflections.rb
create mode 100644 config/initializers/mime_types.rb
create mode 100644 config/initializers/wrap_parameters.rb
create mode 100644 config/locales/en.yml
create mode 100644 config/puma.rb
create mode 100644 config/routes.rb
create mode 100644 config/secrets.yml
create mode 100644 config/spring.rb
create mode 100644 db/seeds.rb
create mode 100644 lib/assets/.keep
create mode 100644 lib/tasks/.keep
create mode 100644 log/.keep
create mode 100644 package.json
create mode 100644 public/404.html
create mode 100644 public/422.html
create mode 100644 public/500.html
create mode 100644 public/apple-touch-icon-precomposed.png
create mode 100644 public/apple-touch-icon.png
create mode 100644 public/favicon.ico
create mode 100644 public/robots.txt
create mode 100644 test/application_system_test_case.rb
create mode 100644 test/controllers/.keep
create mode 100644 test/fixtures/.keep
create mode 100644 test/fixtures/files/.keep
create mode 100644 test/helpers/.keep
create mode 100644 test/integration/.keep
create mode 100644 test/mailers/.keep
create mode 100644 test/models/.keep
create mode 100644 test/system/.keep
create mode 100644 test/test_helper.rb
create mode 100644 tmp/.keep
create mode 100644 vendor/.keep
ec2-user:~/environment/hello_app (master) $ 

いいね(いいね)

ちな-mをつけると直接コメントがつけれて、-mがないとエディタが立ち上がっちゃう
railsチュートリアルでは常に-m使う

git logコマンドでコミットメッセージの履歴を参照できる

ログ
-------------------
ec2-user:~/environment/hello_app (master) $ git log
commit ナイシュ (HEAD -> master)
Author: ナイショ <ナイショ>
Date:   Thu Dec 26 14:07:04 2019 +0000
   Initialize repository
ec2-user:~/environment/hello_app (master) $ 
-------------------

ログが長い場合はqで終了できる
gitのlessコマンドについて書かれてるけどなんか説明書いてないから飛ばす

・1 4 2 Gitのメリット

うっかり削除した場合でもgit checkout -fで元通りになる
-fは強制的に上書きしますよって意味


・1 4 3 Bitbucket

似たようなサービスでGitHubあるけど、今回はわざわざBitbucket使うって言ってる
どっちもgitリポジトリのホスティングと共同作業を行うことができ、リポジトリの表示と検索を行いやすくしてくれる
重要な違いは以下の通り
GitHub :リポジトリを一般公開する場合は無料、公開しない場合は有料
Bitbucket:共同作業者が一定数以下ならリポジトリを公開しなくても無料、共同作業者が一定数を超えると有料
セキュリティの観点から、今回はGitHubじゃなくてBitbucket使いましょうねって言われてる

あ!でもなんかGitHubでも無料化されるっぽいからGitHubでもいいって言われてる
まあいいや、Bitbucketつかお!

そのときの備忘録を以下のnoteにまとめました
開発環境構築備忘録 BitBucket編
https://note.com/el93019205/n/n148d8031086d

git config --global user.name で名前が設定されていることを確認→OK
git config --global user.email でemailが設定されていることを確認→OK

git remote -vで
origin git@bitbucket.org:秘密/hello_app.git (fetch)
origin git@bitbucket.org:秘密/hello_app.git (push)
となっていることを確認

cd ~/.ssh
lsで鍵が作成されていることを確認
だいたいはauthorized_keys known_hostsの2つのはず
2つしかなかったら下記実行
ssh-keygen
Enterを3連続で
再度lsでid_rsaとid_rsa.pubが作成されているのを確認
.pubがついてるほうが公開鍵でそうでないほうが秘密鍵
cat id_rsa.pub
で暗号化された文字列が返ってくる
Bitbucketの左下の〇からBitbucket settingsを開く
SSHを開く
鍵を開く
名前のほうはたぶんなんでもいい
keyにさっきの暗号化された文字列をコピペ

もう一度cloud9に戻る
パスをきっちり指定する
cd ~/environment/hello_app

git remote add origin git@bitbucket.org:アカウント名/hello_app.gitでgitbucketと繋ぐ
git add -Aで変更ファイルを追加
git statusで追加されたファイルを確認
git commit -m "test"で変更内容をつける
git logで変更内容を確認
git push -u origin masterでBitbucketにプッシュ

ログ
-------------------
Counting objects: 89, done.
Compressing objects: 100% (75/75), done.
Writing objects: 100% (89/89), 22.03 KiB | 1.16 MiB/s, done.
Total 89 (delta 4), reused 0 (delta 0)
To bitbucket.org:EL93019205/hello_app.git
* [new branch]      master -> master
Branch master set up to track remote branch master from origin.

※以下のことに注意!
hello_appディレクトリに鍵が作成されたらNG!
鍵の名称がid_rsaとid_rsa.pubでなかったらNG!(たぶん)

・1 4 4 ブランチ、編集、コミット、マージ

readme.mdは自動的に表示されるよ
mdはmarkdownの意味
bitbucketでもgithubでも自動的にHTMLに変換してくれる

【ブランチについて】
親リポジトリはmasterブランチと呼ばれる
トピックブランチ(一時的なブランチ)は以下のコマンドで作成する
※ -bは新規作成してブランチを切り替えるのを一気にやってくれる
git checkout -b modify-README
ブランチを表示する
git branch
※必ずcd ~/environment/hello_app/ を実行してパスをきっちりする

-b modify-READMEを実行したときのログ


Switched to a new branch 'modify-README'

git branchを実行したときのログ


 master
* modify-README

※*が今のブランチ

【編集について】
hello_app以下のreadme.mdを修正
# Ruby on Rails Tutorial

## "hello, world!"

This is the first application for the
[*Ruby on Rails Tutorial*](https://railstutorial.jp/)
by [Michael Hartl](http://www.michaelhartl.com/). Hello, world!

【コミットについて】
git statusで確認


On branch modify-README
nothing to commit, working tree clean

あ、readme.mdをセーブするの忘れてた
セーブしてもう一度git statusで確認


On branch modify-README
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:   README.md
no changes added to commit (use "git add" and/or "git commit -a")

git add -Aを実行しなくても、以下のようにすることで一気にコメントまでつけてコミットできる
git commit -a -m "Improve the README file"


[modify-README 96cad81] Improve the README file
1 file changed, 5 insertions(+), 22 deletions(-)

【マージについて】
以下の順で行う
①マスターに切り替える
git checkout master
②ブランチの状態を確認してみる
git branch
③マスターにトピックブランチをマージしてみる
git merge modify-README
④トピックブランチを削除
git branch -d modify-README
※マージしていないけど削除する場合は以下の通り
git branch -D modify-README

最後にgit push
※git push origin masterを1度行っているとgit pushでマスターにpushしてくれるっぽい

bitbacketで更新されたことを確認!!


・1 5 デプロイする

Phusion PassengerというApacheやNginxなどのWebサーバ用のモジュールを実行できるさまざまな共有ホストや仮想プライベートサーバ(VPS)
一通りのデプロイ環境を提供するEngine YardやRails Machine
クラウドサービスを提供するEngine Yard CloudやHerokuがある

railsチュートリアルではHerokuを使ってみる


・1 5 1 Herokuのセットアップ

HerokuはPostgreSQLを使ってる
gemfileを修正

group :production do
gem 'pg', '0.20.0'
end

--without productionをつけると本番用gemがインストールされないので安心(?)
bundle install --without production

ログ
-------------------
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Using rake 13.0.1
Using concurrent-ruby 1.1.5
Using i18n 1.7.0
Using minitest 5.13.0
Using thread_safe 0.3.6
Using tzinfo 1.2.6
Using activesupport 5.1.6
Using builder 3.2.4
Using erubi 1.9.0
Using mini_portile2 2.4.0
Using nokogiri 1.10.7
Using rails-dom-testing 2.0.3
Using crass 1.0.5
Using loofah 2.4.0
Using rails-html-sanitizer 1.3.0
Using actionview 5.1.6
Using rack 2.0.8
Using rack-test 1.1.0
Using actionpack 5.1.6
Using nio4r 2.5.2
Using websocket-extensions 0.1.4
Using websocket-driver 0.6.5
Using actioncable 5.1.6
Using globalid 0.4.2
Using activejob 5.1.6
Using mini_mime 1.0.2
Using mail 2.7.1
Using actionmailer 5.1.6
Using activemodel 5.1.6
Using arel 8.0.0
Using activerecord 5.1.6
Using bindex 0.8.1
Using bundler 1.17.3
Using byebug 9.0.6
Using coffee-script-source 1.12.2
Using execjs 2.7.0
Using coffee-script 2.4.1
Using method_source 0.9.2
Using thor 1.0.1
Using railties 5.1.6
Using coffee-rails 4.2.2
Using ffi 1.11.3
Using multi_json 1.14.1
Using jbuilder 2.6.4
Using jquery-rails 4.3.1
Using rb-fsevent 0.10.3
Using rb-inotify 0.10.1
Using ruby_dep 1.5.0
Using listen 3.1.5
Using puma 3.9.1
Using sprockets 3.7.2
Using sprockets-rails 3.2.1
Using rails 5.1.6
Using sass-listen 4.0.0
Using sass 3.7.4
Using tilt 2.0.10
Using sass-rails 5.0.6
Using spring 2.0.2
Using spring-watcher-listen 2.0.1
Using sqlite3 1.3.13
Using turbolinks-source 5.2.0
Using turbolinks 5.0.1
Using uglifier 3.2.0
Using web-console 3.5.1
Bundle complete! 15 Gemfile dependencies, 64 gems now installed.
Gems in the group production were not installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.

git commit -a -m "Update Gemfile for Heroku"
でコミットする

herokuのバージョンを調べる
heroku -v
heroku --version

ログ


bash: heroku: command not found

いやインストールされてへんやんけ!
インストールは下記
source <(curl -sL https://cdn.learnenough.com/heroku_install)

ログ


 % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                Dload  Upload   Total   Spent    Left  Speed
100 25.9M  100 25.9M    0     0  69.7M      0 --:--:-- --:--:-- --:--:-- 69.5M

もういちどheroku --version

ログ


heroku/7.35.1 linux-x64 node-v12.13.0

んーrailsチュートリアルだと


heroku-cli/6.15.5 (linux-x64) node-v9.2.1


だけどまあいいか!

以下のコマンドでSSHキーを追加
heroku login --interactive

なんかメアドとパスワードの入力求められたんやが・・・
以下で登録する
https://jp.heroku.com/

いろいろ入力して登録
しかしメールくるまでに15分くらいかかるらしいとのこと
待つか。

待ったらメール来たのでパスワード設定
パスワードには記号も含めないといけないパターンなのでちょっとめんどい

リベンジ!
heroku login --interactive
mail:ナイショ
pass:ナイショ
成功!

heroku keys:add
Uploading /home/ec2-user/.ssh/id_rsa.pub SSH key... done
成功

続いてHerokuに新しいアプリケーション作成
heroku create
Creating app... done, damp-dusk-12500
https://damp-dusk-12500.herokuapp.com/ | https://git.heroku.com/damp-dusk-12500.git
成功!

これで
https://damp-dusk-12500.herokuapp.com/
で自分のwebページが表示されるように!

・1 5 2 Herokuにデプロイする (1)

git push heroku master
でHerokuにpushする!

ログ
-------------------
Counting objects: 95, done.
Compressing objects: 100% (81/81), done.
Writing objects: 100% (95/95), 22.67 KiB | 1.26 MiB/s, done.
Total 95 (delta 7), 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.5.7
remote: -----> Vendoring libpq 5.12.1
remote: -----> Removing BUNDLED WITH version in the Gemfile.lock
remote: -----> Installing dependencies using bundler 1.17.3
remote:        Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
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: 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 damp-dusk-12500.
remote: 
To https://git.heroku.com/damp-dusk-12500.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/damp-dusk-12500.git'

失敗してる!
https://qiita.com/seiya2130/items/999b5512fa5aa7121784
によると、

bundle install --without production
の実行が必要らしい

それやったあとやったらできた!

ログ
-------------------
Counting objects: 98, done.
Compressing objects: 100% (84/84), done.
Writing objects: 100% (98/98), 22.96 KiB | 1.21 MiB/s, done.
Total 98 (delta 9), 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.5.7
remote: -----> Vendoring libpq 5.12.1
remote: -----> Removing BUNDLED WITH version in the Gemfile.lock
remote: -----> Installing dependencies using bundler 1.17.3
remote:        Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
remote:        The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
remote:        Fetching gem metadata from https://rubygems.org/............
remote:        Fetching rake 13.0.1
remote:        Installing rake 13.0.1
remote:        Fetching minitest 5.13.0
remote:        Fetching concurrent-ruby 1.1.5
remote:        Fetching thread_safe 0.3.6
remote:        Installing minitest 5.13.0
remote:        Installing thread_safe 0.3.6
remote:        Installing concurrent-ruby 1.1.5
remote:        Fetching builder 3.2.4
remote:        Installing builder 3.2.4
remote:        Fetching erubi 1.9.0
remote:        Installing erubi 1.9.0
remote:        Fetching mini_portile2 2.4.0
remote:        Installing mini_portile2 2.4.0
remote:        Fetching crass 1.0.5
remote:        Installing crass 1.0.5
remote:        Fetching rack 2.0.8
remote:        Fetching nio4r 2.5.2
remote:        Installing rack 2.0.
remote:        Installing nio4r 2.5.2 with native extensions
remote:        Fetching websocket-extensions 0.1.4
remote:        Installing websocket-extensions 0.1.4
remote:        Fetching mini_mime 1.0.2
remote:        Installing mini_mime 1.0.2
remote:        Fetching arel 8.0.0
remote:        Installing arel 8.0.
remote:        Using bundler 1.17.3
remote:        Fetching coffee-script-source 1.12.2
remote:        Installing coffee-script-source 1.12.2
remote:        Fetching execjs 2.7.0
remote:        Fetching method_source 0.9.2
remote:        Installing execjs 2.7.0
remote:        Installing method_source 0.9.2
remote:        Fetching thor 1.0.1
remote:        Fetching ffi 1.11.3
remote:        Installing thor 1.0.1
remote:        Fetching multi_json 1.14.1
remote:        Installing ffi 1.11.3 with native extensions
remote:        Installing multi_json 1.14.1
remote:        Fetching pg 0.20.0
remote:        Installing pg 0.20.0 with native extensions
remote:        Fetching puma 3.9.1
remote:        Installing puma 3.9.1 with native extensions
remote:        Fetching rb-fsevent 0.10.3
remote:        Installing rb-fsevent 0.10.3
remote:        Fetching tilt 2.0.10
remote:        Installing tilt 2.0.10
remote:        Fetching turbolinks-source 5.2.0
remote:        Installing turbolinks-source 5.2.0
remote:        Fetching tzinfo 1.2.6
remote:        Installing tzinfo 1.2.6
remote:        Fetching nokogiri 1.10.7
remote:        Installing nokogiri 1.10.7 with native extensions
remote:        Fetching i18n 1.7.0
remote:        Installing i18n 1.7.0
remote:        Fetching websocket-driver 0.6.5
remote:        Installing websocket-driver 0.6.5 with native extensions
remote:        Fetching mail 2.7.1
remote:        Installing mail 2.7.1
remote:        Fetching rack-test 1.1.0
remote:        Installing rack-test 1.1.0
remote:        Fetching sprockets 3.7.2
remote:        Installing sprockets 3.7.2
remote:        Fetching coffee-script 2.4.1
remote:        Installing coffee-script 2.4.1
remote:        Fetching uglifier 3.2.0
remote:        Installing uglifier 3.2.0
remote:        Fetching turbolinks 5.0.1
remote:        Installing turbolinks 5.0.1
remote:        Fetching rb-inotify 0.10.1
remote:        Installing rb-inotify 0.10.1
remote:        Fetching activesupport 5.1.6
remote:        Installing activesupport 5.1.6
remote:        Fetching sass-listen 4.0.0
remote:        Installing sass-listen 4.0.0
remote:        Fetching globalid 0.4.2
remote:        Installing globalid 0.4.2
remote:        Fetching activemodel 5.1.6
remote:        Installing activemodel 5.1.6
remote:        Fetching jbuilder 2.6.4
remote:        Installing jbuilder 2.6.4
remote:        Fetching sass 3.7.4
remote:        Installing sass 3.7.4
remote:        Fetching activejob 5.1.6
remote:        Installing activejob 5.1.6
remote:        Fetching activerecord 5.1.6
remote:        Installing activerecord 5.1.6
remote:        Fetching rails-dom-testing 2.0.3
remote:        Fetching loofah 2.4.0
remote:        Installing rails-dom-testing 2.0.3
remote:        Installing loofah 2.4.0
remote:        Fetching rails-html-sanitizer 1.3.0
remote:        Installing rails-html-sanitizer 1.3.0
remote:        Fetching actionview 5.1.6
remote:        Installing actionview 5.1.6
remote:        Fetching actionpack 5.1.6
remote:        Installing actionpack 5.1.6
remote:        Fetching actionmailer 5.1.6
remote:        Fetching railties 5.1.6
remote:        Fetching actioncable 5.1.6
remote:        Installing actioncable 5.1.6
remote:        Installing actionmailer 5.1.6
remote:        Installing railties 5.1.6
remote:        Fetching sprockets-rails 3.2.1
remote:        Installing sprockets-rails 3.2.1
remote:        Fetching jquery-rails 4.3.1
remote:        Fetching rails 5.1.6
remote:        Fetching coffee-rails 4.2.2
remote:        Installing rails 5.1.6
remote:        Installing coffee-rails 4.2.2
remote:        Fetching sass-rails 5.0.6
remote:        Installing sass-rails 5.0.6
remote:        Installing jquery-rails 4.3.1
remote:        Bundle complete! 16 Gemfile dependencies, 57 gems now installed.
remote:        Gems in the groups development and test were not installed.
remote:        Bundled gems are installed into `./vendor/bundle`
remote:        Post-install message from i18n:
remote:        
remote:        HEADS UP! i18n 1.1 changed fallbacks to exclude default locale.
remote:        But that may break your application.
remote:        
remote:        Please check your Rails app for 'config.i18n.fallbacks = true'.
remote:        If you're using I18n (>= 1.1.0) and Rails (< 5.2.2), this should be
remote:        'config.i18n.fallbacks = [I18n.default_locale]'.
remote:        If not, fallbacks will be broken in your app by I18n 1.1.x.
remote:        
remote:        For more info see:
remote:        https://github.com/svenfuchs/i18n/releases/tag/v1.1.0
remote:        
remote:        Post-install message from sass:
remote:        
remote:        Ruby Sass has reached end-of-life and should no longer be used.
remote:        
remote:        * If you use Sass as a command-line tool, we recommend using Dart Sass, the new
remote:          primary implementation: https://sass-lang.com/install
remote:        
remote:        * If you use Sass as a plug-in for a Ruby web framework, we recommend using the
remote:          sassc gem: https://github.com/sass/sassc-ruby#readme
remote:        
remote:        * For more details, please refer to the Sass blog:
remote:          https://sass-lang.com/blog/posts/7828841
remote:        
remote:        Bundle completed (43.50s)
remote:        Cleaning up the bundler cache.
remote: -----> Installing node-v10.15.3-linux-x64
remote: -----> Detecting rake tasks
remote: -----> Preparing app for Rails asset pipeline
remote:        Running: rake assets:precompile
remote:        Yarn executable was not detected in the system.
remote:        Download Yarn at https://yarnpkg.com/en/docs/install
remote:        I, [2019-12-27T14:48:55.725693 #1473]  INFO -- : Writing /tmp/build_8eed67d9cd6c472636118774d43f5577/public/assets/application-7e084e44b9a13db0cda25bad2ac6fdbbfe31462ec93176e245cd0bcbc079f436.js
remote:        I, [2019-12-27T14:48:55.726361 #1473]  INFO -- : Writing /tmp/build_8eed67d9cd6c472636118774d43f5577/public/assets/application-7e084e44b9a13db0cda25bad2ac6fdbbfe31462ec93176e245cd0bcbc079f436.js.gz
remote:        I, [2019-12-27T14:48:55.736949 #1473]  INFO -- : Writing /tmp/build_8eed67d9cd6c472636118774d43f5577/public/assets/application-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css
remote:        I, [2019-12-27T14:48:55.737094 #1473]  INFO -- : Writing /tmp/build_8eed67d9cd6c472636118774d43f5577/public/assets/application-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css.gz
remote:        Asset precompilation completed (2.86s)
remote:        Cleaning assets
remote:        Running: rake assets:clean
remote: -----> Detecting rails configuration
remote: 
remote: ###### WARNING:
remote: 
remote:        You have not declared a Ruby version in your Gemfile.
remote:        To set your Ruby version add this line to your Gemfile:
remote:        ruby '2.5.7'
remote:        # See https://devcenter.heroku.com/articles/ruby-versions for more information.
remote: 
remote: 
remote: ###### WARNING:
remote: 
remote:        Replacing libpq with version libpq 5.12.1
remote:        
remote:        This version includes a bug fix that can cause an exception
remote:        on boot for applications with incorrectly configured connection
remote:        values. For more information see:
remote:        
remote:          https://devcenter.heroku.com/articles/libpq-5-12-1-breaking-connection-behavior
remote:        
remote:        If your application breaks you can rollback to your last build.
remote:        You can also temporarially opt out of this behavior by setting:
remote:        
remote:        ```
remote:        $ heroku config:set HEROKU_SKIP_LIBPQ12=1
remote:        ```
remote:        
remote:        In the future libpq 5.12 will be the default on the platform and
remote:        you will not be able to opt-out of the library. For more information see:
remote:        
remote:          https://devcenter.heroku.com/articles/libpq-5-12-1-breaking-connection-behavior
remote: 
remote: 
remote: ###### WARNING:
remote: 
remote:        Detecting rails configuration failed
remote:        set HEROKU_DEBUG_RAILS_RUNNER=1 to debug
remote: 
remote: 
remote: ###### WARNING:
remote: 
remote:        No Procfile detected, using the default web server.
remote:        We recommend explicitly declaring how to boot your server process via a Procfile.
remote:        https://devcenter.heroku.com/articles/ruby-default-web-server
remote: 
remote: 
remote: 
remote: -----> Discovering process types
remote:        Procfile declares types     -> (none)
remote:        Default types for buildpack -> console, rake, web
remote: 
remote: -----> Compressing...
remote:        Done: 35.5M
remote: -----> Launching...
remote:        Released v6
remote:        https://damp-dusk-12500.herokuapp.com/ deployed to Heroku
remote: 
remote: Verifying deploy... done.
To https://git.heroku.com/damp-dusk-12500.git
* [new branch]      master -> master

・1 5 3 Herokuにデプロイする (2)

なんもなし

・1 5 4 Herokuコマンド

アプリケーションの名前を変えてみる
heroku rename jun-killer-rails

自分のwebサイトできたーーーーーーーーーーーーーーーーーーーー
ーーーーーーーーーーーーーーーーー!!!!!!
https://jun-killer-rails.herokuapp.com/

heroku helpで色んなコマンド出してみる

ログ
-------------------
CLI to interact with Heroku
VERSION
 heroku/7.35.1 linux-x64 node-v12.13.0
USAGE
 $ heroku [COMMAND]
COMMANDS
 access          manage user access to apps
 addons          tools and services for developing,
                 extending, and operating your app
 apps            manage apps on Heroku
 auth            check 2fa status
 authorizations  OAuth authorizations
 autocomplete    display autocomplete installation
                 instructions
 base
 buildpacks      scripts used to compile apps
 certs           a topic for the ssl plugin
 ci              run an application test suite on Heroku
 clients         OAuth clients on the platform
 config          environment variables of apps
 container       Use containers to build and deploy
                 Heroku apps
 domains         custom domains for apps
 drains          forward logs to syslog or HTTPS
 features        add/remove app features
 git             manage local git repository for app
 help            display help for heroku
 keys            add/remove account ssh keys
 labs            add/remove experimental features
 local           run Heroku app locally
 logs            display recent log output
 maintenance     enable/disable access to app
 members         manage organization members
 notifications   display notifications
 orgs            manage organizations
 pg              manage postgresql databases
 pipelines       manage pipelines
 plugins         list installed plugins
 ps              Client tools for Heroku Exec
 psql            open a psql shell to the database
 redis           manage heroku redis instances
 regions         list available regions for deployment
 releases        display the releases for an app
 reviewapps      manage reviewapps in pipelines
 run             run a one-off process inside a Heroku
                 dyno
 sessions        OAuth sessions
 spaces          manage heroku private spaces
 status          status of the Heroku platform
 teams           manage teams
 update          update the Heroku CLI
 webhooks        list webhooks on an app

ふーん(鼻ほじ)(見てない)


・1 6 最後に

#Railsチュートリアル ハッシュタグ使うと他の学習者と繋がれるよ

・1 6 1 本章のまとめ

ruby on railsはweb開発のためのフレームワーク
rubyで作られた
事前設定済みのクラウド環境を利用することで、railsのインストール、アプリケーションの生成、生成されたファイルの編集を簡単に行うことができる
railsにはrailsという名前のコマンドラインコマンドがあり、rails newで新しいアプリケーションを生成したり、rails serverでローカルサーバーを実行したりできる
コントローラのアクションを追加したり、ルートルーティングを変更したりするだけでサクっとアプリを作れる
gitによるバージョン管理を導入してBitBucketの非公開リポジトリにプッシュする理由はデータを無くさないためと、他の開発者との共同作業を行えるようにするため
作成したアプリをHerokuの本番環境にデプロイする

・専門用語

MITライセンス
MITはマサチューセッツ工科大学?
誰でも自由に無料でソフトウェアを使用、改造、再配布、商用利用、有料販売することができるオープンソースのライセンス


DSL
Doain specific Language
ドメイン固有言語
特定のタスク向けに設計されたコンピュータ言語


コントリビューター
Contributor
投稿者


カンファレンス
conference
会議


テストスイート
conference


IDE
Integrated development environment 統合開発環境 


Confirm
確認


Verify
確認


bundle


次は第二章!開発環境構築つらかったー(泣)

この記事が気に入ったらサポートをしてみませんか?