0
0

More than 3 years have passed since last update.

Ruby on Railsのチュートリアル ~第2章Toyアプリケーション~

Posted at

はじめに

webアプリケーションを作るための学習記録
(マッチングアプリを作る予定)

こちらのチュートリアルを片っ端から進めていく
【Ruby on Rails チュートリアル】
https://railstutorial.jp/

第2章Toyアプリケーション

まとめ

  • Scaffold機能でコードを自動生成すると、Webのあらゆる部分からモデルデータにアクセスしてやりとりできるようになる
  • Scaffoldは何よりも手っ取り早いのがとりえだが、これを元にRailsを理解するには向いていない
  • RailsではWebアプリケーションの構成にMVC (Model-View-Controller) というモデルを採用している
  • Railsが解釈するRESTには、標準的なURLセットと、データモデルとやりとりするためのコントローラアクションが含まれている
  • Railsではデータのバリデーション (validation) がサポートされており、データモデルの属性の値に制限をかけることができる
  • Railsには、さまざまなデータモデル同士を関連付けを定義するための組み込み関数が多数用意されている
  • Railsコンソールを使うと、コマンドラインからRailsアプリケーションとやりとりすることができる

所感

  • RESTもうちょっと理解したい。
  • Scaffoldすごい。POC的に簡単に作るときには重宝しそう
  • railsのwebフレームワーク(MVCモデル)の簡潔さに感動している、MとVとCが明確で、余計なもののなさを感じる

途中参考にしたページ

使用したコマンド

rails 5.1.6 new toy_app
bundle install --without production
bundle update
git init
git add -A
git commit -m "Initialize repository"
git remote add origin git@github.com:アカウント名/リポジトリ名.git
git push -u origin --all
cd /home/ec2-user/environment/toy_app
rails server

git add -A
git commit -am "Add hello"
git status
heroku create リポジトリ名
git push heroku master

rails generate scaffold User name:string email:string
rails db:migrate
rails server
rails routes

rails generate scaffold Micropost content:text user_id:integer
rails db:migrate
rails routes

rails console
first_user = User.first
first_user.microposts
micropost = first_user.microposts.first
micropost.user

git status
git add -A
git commit -m "Finish toy app"
git push
git push heroku
heroku run rails db:migrate

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0