Progate【Ruby on Rails5 道場コース I】に沿って
アウトプットも兼ねて実際にアプリ作成していこうと思いきや
ちょっとつまづいた部分があったので記録していきます。
新規アプリ作成
ターミナルでrails new 【新規作成したいアプリ名】
を入力。
(例えば私の場合はrails new agametter_app
)※ひたすら推しを崇める言葉をツイートするゴミアプリ
$ rails new 【新規作成したいアプリ名】
create
create README.md
create Rakefile
create .ruby-version
create config.ru
create .gitignore
create Gemfile
run git init from "."
*
*
(省略)
*
*
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`.
run bundle exec spring binstub --all
* bin/rake: Spring inserted
* bin/rails: Spring inserted
rails webpacker:install
sh: node: command not found
sh: nodejs: command not found
Node.js not installed. Please download and install Node.js https://nodejs.org/en/download/
なんとか作成できたようです。
(後半辺りで「Node.jsダウンロードしろ」って言われてることに後から気付くという…。)
作成したアプリに入る
アプリ名の頭にcd
を付けて入る
$ cd 【新規作成したアプリ名】
※自分のユーザー名の後ろにアプリ名が入ればOK
↓ ↓ ↓
lancai@oja 【新規作成したアプリ名】 $
早速サーバーを立ち上げよう
railsのサーバーを立ち上げます。
$ rails s
いい調子に進んでる…!
=> Booting Puma
=> Rails 6.0.2.1 application starting in development
=> Run `rails server --help` for more startup options
Exiting
Traceback (most recent call last):
77: from bin/rails:3:in `<main>'
76: from bin/rails:3:in `load'
75: from /Users/lancai/agametter_app/bin/spring:15:in `<top (required)>'
74: from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
73: from
*
*
(省略)
*
*
1: from /Library/Ruby/Gems/2.6.0/gems/webpacker-4.2.2/lib/webpacker/configuration.rb:91:in `load'
/Library/Ruby/Gems/2.6.0/gems/webpacker-4.2.2/lib/webpacker/configuration.rb:95:in `rescue in load': Webpacker configuration file not found /Users/lancai/agametter_app/config/webpacker.yml. Please run rails webpacker:install Error: No such file or directory @ rb_sysopen - /Users/lancai/agametter_app/config/webpacker.yml (RuntimeError)
lancai@oja agametter_app % rails webpacker:install
sh: node: command not found
sh: nodejs: command not found
Node.js not installed. Please download and install Node.js https://nodejs.org/en/download/
「Node.js not installed. Please download and install Node.js https://nodejs.org/en/download/」
一番下の行でどうやら「Node.js
をダウンロードしろ」と命令されているようなので、指定されたURLに飛んでダウンロードします。
自分が使用しているOSを選びます。
ダウンロードができたらインストールします。
(インストールできない場合は「システムの環境設定」→「セキュリティとプライバシー」→「一般」タブ→左下のカギアイコン→パスワード認証→ダウンロードしたアプリケーションの実行許可により、インストールが可能となります。)
webpackerのインストール
さて、インストールが終わったのでターミナルに入力していきます。
$ rails webpacker:install
Yarn not installed. Please download and install Yarn from https://yarnpkg.com/lang/en/docs/install/
今度はYarn
が必要みたいなので
下記を入力してインストールしていきます。
$ brew install yarn
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> New Formulae
awscli@1 katago
==> Updated Formulae
ruby-build ✔ jsonschema2pojo
abcmidi kube-aws
*
*
(省略)
*
*
├─ unpipe@1.0.0
├─ utils-merge@1.0.1
├─ wbuf@1.7.3
├─ webpack-dev-middleware@3.7.2
├─ webpack-dev-server@3.10.3
├─ websocket-extensions@0.1.3
├─ ws@6.2.1
├─ yargs-parser@11.1.1
└─ yargs@12.0.5
✨ Done in 11.25s.
Webpacker successfully installed 🎉 🍰
わあ、絵文字がカワイイ…(ほっこり)
インストールが完了したので、サーバー立ち上げに戻ります。
$ rails s
=> Booting Puma
=> Rails 6.0.2.1 application starting in development
=> Run `rails server --help` for more startup options
Puma starting in single mode...
* Version 4.3.1 (ruby 2.6.3-p62), codename: Mysterious Traveller
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://127.0.0.1:3000
* Listening on tcp://[::1]:3000
Use Ctrl-C to stop
Started GET "/home/top" for ::1 at 2020-02-16 21:23:36 +0900
(3.2ms) SELECT sqlite_version(*)
*
*
(省略)
*
*
puma (4.3.1) lib/puma/thread_pool.rb:134:in `block in spawn_thread'
Started GET "/" for ::1 at 2020-02-16 21:23:48 +0900
Processing by Rails::WelcomeController#index as HTML
Rendering /Library/Ruby/Gems/2.6.0/gems/railties-6.0.2.1/lib/rails/templates/rails/welcome/index.html.erb
Rendered /Library/Ruby/Gems/2.6.0/gems/railties-6.0.2.1/lib/rails/templates/rails/welcome/index.html.erb (Duration: 9.6ms | Allocations: 197)
Completed 200 OK in 13ms (Views: 10.6ms | ActiveRecord: 0.0ms | Allocations: 950)
URL http://localhost:3000/
にアクセスして写真のようなページが表示されたらサーバーの立ち上げは無事成功!ということになります。
ひとまず、お疲れ様でした