【6日目】【1日20分のRailsチュートリアル】Toyアプリケーション作成の下準備
今日から第2章。
新しいアプリケーションを作ります。
第2章 Toyアプリケーション
この章だけscaffoldジェネレータというスクリプトでアプリケーションを生成する。
2.1 アプリケーションの計画
新しいアプリケーションを作成する準備。
第1章と同じようにrails new
して
$ cd ~/workspace $ rails _4.2.2_ new toy_app $ cd toy_app/
Gemfileを更新して保存。
bundle install
も。
$ bundle install --without production
ここで新しいアプリケーション用のGitリポジトリを作成します。
Bitbucketでリポジトリ作成。
リポジトリの説明も追加してみる。(別になくてもいい)
「A toy demo app for the Ruby on Rails Tutorial」
作成したリポジトリにpush。
$ git remote add origin git@bitbucket.org:<ユーザー名>/toy_app.git $ git push -u origin --all
お次は「1.3.4 Hello, world!」と同内容を新しいアプリケーションにも対応。
/toy_app/app/controllers/application_controller.rb
def hello render text: "hello, world!" end
/toy_app/config/routes.rb
root 'application#hello'
念のためローカル環境で動作確認してみた。大丈夫だった。
$ cd toy_app/ $ rails server -b $IP -p $PORT
問題ないのでGitコミット。
Bitbucketにもpushしておく。
$ git commit -am "Add hello"
$ git push -u origin --all
本番環境(Heroku)にもアップ。
$ heroku create $ git push heroku master
これで下準備完了。
第1章を一通り復讐したような内容でした。
今日の作業時間は【24分】でした。
次は「2.1.1 ユーザーのモデル設計」から。