Railsチュートリアル第2章(2周目)ユーザー登録が1行で?
2周目の目標は「14章までざっくり行う」です。
理解度は50%を目安にしているので、演習や細かいところはすっ飛ばします。
Railsチュートリアル第1章(2周目) はこちら。
今回の目標:第2章をざっくり行う
公式はこちら→ 第2章 Toyアプリケーション
約1時間で終わらせます。
必要なもの
・AWS (Cloud9)アカウント
・Bitbucket アカウント
(GitHubでも良いが、今回は忠実に進めていく)
・Heroku アカウント
行ったこと
scaffoldを使って、
ユーザー新規登録とマイクロポスト(140文字以下のつぶやき)作成が
できるようになりました。
Herokuに反映しました。
つまずいたこと
bundle install
エラーが起きました。
Running
bundle update
will rebuild your snapshot from scratch, using only the gems in your Gemfile, which may resolve the conflict.
よくみたらGemfile編集を間違えてました。
前回作ったGemfileと同じようなのでコピペし、再度bundle install。
解決しました。
git remote add origin
git pushしたら怒られました。
repository does not exist.
fatal: Could not read from remote repository.Please make sure you have the correct access rights
and the repository exists.
git remote add origin git@bitbucket.org:〇〇/toy_app.git
の際に、「toy_app.git」じゃなくてなぜか「toy_app/src」と間違えていました。
なので、一回git remote addを取り消します。
1 2 3 |
git remote -v git remote rm origin git remote -v |
無事削除されたので、再度git remote addします。
実行コマンド
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
$ cd ~/environment $ rails _5.1.6_ new toy_app $ cd toy_app/ $ bundle install --without production $ bundle install --without production $ git init $ git add -A $ git commit -m "Initialize repository" $ git remote add origin git@bitbucket.org:<username>/toy_app.git $ git push -u origin --all $ git remote -v $ git remote rm origin $ git remote -v $ git commit -am "Add hello" $ heroku --version $ source <(curl -sL https://cdn.learnenough.com/heroku_install) $ heroku --version $ heroku login $ heroku login --interactive $ heroku keys:add $ heroku create $ git push heroku master $ rails generate scaffold User name:string email:string $ rails db:migrate $ rails server $ rails generate scaffold Micropost content:text user_id:integer $ rails db:migrate $ rails server $ rails console first_user = User.first first_user.microposts first_user.microposts.first micropost.user exit $ git status $ git add -A $ git commit -m "Finish toy app" $ git push $ git push heroku $ heroku open |
まとめ
すごいよ、scaffold!
手っ取り早く、ユーザー登録とつぶやきなどが
できる状態になりました。
本番反映への流れが大まかに理解できました。
つまずいた2点は、きちんと確認すれば防げます。
なんで「src」って打ち込んだんだろう。
頭が鉄骨鉄筋コンクリートでいっぱいだったのかな。
それともsourceの方かな。
意味がわからないので休憩します。
ここでしか読めない!話題のやめ太郎さんへの質問
やめ太郎さんが、面白おかしく記事を書けるのは
前職がコールセンターだったから??
Twitterも要チェック☆
ほかにも50名以上のお話が読めるのは、このブログだけ!