ror 101: session 1
DESCRIPTION
Part 1 of 6TRANSCRIPT
![Page 1: RoR 101: Session 1](https://reader033.vdocuments.site/reader033/viewer/2022051514/54bd178d4a7959ff308b4647/html5/thumbnails/1.jpg)
Building Web Apps with Rails
![Page 2: RoR 101: Session 1](https://reader033.vdocuments.site/reader033/viewer/2022051514/54bd178d4a7959ff308b4647/html5/thumbnails/2.jpg)
Hello
![Page 3: RoR 101: Session 1](https://reader033.vdocuments.site/reader033/viewer/2022051514/54bd178d4a7959ff308b4647/html5/thumbnails/3.jpg)
![Page 4: RoR 101: Session 1](https://reader033.vdocuments.site/reader033/viewer/2022051514/54bd178d4a7959ff308b4647/html5/thumbnails/4.jpg)
![Page 5: RoR 101: Session 1](https://reader033.vdocuments.site/reader033/viewer/2022051514/54bd178d4a7959ff308b4647/html5/thumbnails/5.jpg)
![Page 6: RoR 101: Session 1](https://reader033.vdocuments.site/reader033/viewer/2022051514/54bd178d4a7959ff308b4647/html5/thumbnails/6.jpg)
What about you?
![Page 7: RoR 101: Session 1](https://reader033.vdocuments.site/reader033/viewer/2022051514/54bd178d4a7959ff308b4647/html5/thumbnails/7.jpg)
The Course
![Page 8: RoR 101: Session 1](https://reader033.vdocuments.site/reader033/viewer/2022051514/54bd178d4a7959ff308b4647/html5/thumbnails/8.jpg)
Hello Ruby!
Hello Rails
![Page 9: RoR 101: Session 1](https://reader033.vdocuments.site/reader033/viewer/2022051514/54bd178d4a7959ff308b4647/html5/thumbnails/9.jpg)
Try Ruby!
Http://tryruby.org
Stop when you see "summary 4" or stuff
about file operations.
Skip to challenge on Classes.
![Page 10: RoR 101: Session 1](https://reader033.vdocuments.site/reader033/viewer/2022051514/54bd178d4a7959ff308b4647/html5/thumbnails/10.jpg)
Ruby, Ruby, Ruby
● Everything is an object
● Chain methods to your heart's content
● Bang! Or no bang?
● Hashes and :symbols
● Key value pairs :key => 'value'
● Blocks { } / do end
● @instance variables
![Page 11: RoR 101: Session 1](https://reader033.vdocuments.site/reader033/viewer/2022051514/54bd178d4a7959ff308b4647/html5/thumbnails/11.jpg)
A Ruby Class
![Page 12: RoR 101: Session 1](https://reader033.vdocuments.site/reader033/viewer/2022051514/54bd178d4a7959ff308b4647/html5/thumbnails/12.jpg)
Our app: FirstFM
![Page 13: RoR 101: Session 1](https://reader033.vdocuments.site/reader033/viewer/2022051514/54bd178d4a7959ff308b4647/html5/thumbnails/13.jpg)
FirstFM
StationsUsers StationLists
![Page 14: RoR 101: Session 1](https://reader033.vdocuments.site/reader033/viewer/2022051514/54bd178d4a7959ff308b4647/html5/thumbnails/14.jpg)
FirstFM
StationsUsers StationLists
![Page 15: RoR 101: Session 1](https://reader033.vdocuments.site/reader033/viewer/2022051514/54bd178d4a7959ff308b4647/html5/thumbnails/15.jpg)
Let's get going
rails new firstfm
rails generate scaffold Station name:string description:text url:string
cd firstfm
rake db:migrate
rails server
![Page 16: RoR 101: Session 1](https://reader033.vdocuments.site/reader033/viewer/2022051514/54bd178d4a7959ff308b4647/html5/thumbnails/16.jpg)
What? How did this happen?
![Page 17: RoR 101: Session 1](https://reader033.vdocuments.site/reader033/viewer/2022051514/54bd178d4a7959ff308b4647/html5/thumbnails/17.jpg)
Rails has generated
● Application defaults, files and settings
● A model to represent the 'Station' entity
● A database table to store stations
● A controller to respond to requests
● Views to show them
![Page 18: RoR 101: Session 1](https://reader033.vdocuments.site/reader033/viewer/2022051514/54bd178d4a7959ff308b4647/html5/thumbnails/18.jpg)
Rails has generated
● Application defaults, files and settings
● A model to represent the 'Station' entity
● A database table to store stations
● A controller to respond to requests
● Views to show them
rails new firstfm
![Page 19: RoR 101: Session 1](https://reader033.vdocuments.site/reader033/viewer/2022051514/54bd178d4a7959ff308b4647/html5/thumbnails/19.jpg)
Rails has generated
● Application defaults, files and settings
● A model to represent the 'Station' entity
● A database table to store stations
● A controller to respond to requests
● Views to show them
rails generate scaffold Station name:string description:text url:string
![Page 20: RoR 101: Session 1](https://reader033.vdocuments.site/reader033/viewer/2022051514/54bd178d4a7959ff308b4647/html5/thumbnails/20.jpg)
Rails has generated
● Application defaults, files and settings
● A model to represent the 'Station' entity
● A database table to store stations
● A controller to respond to requests
● Views to show them
rake db:migrate
![Page 21: RoR 101: Session 1](https://reader033.vdocuments.site/reader033/viewer/2022051514/54bd178d4a7959ff308b4647/html5/thumbnails/21.jpg)
EVERYONE IS ENTITLED TO MY
OPINION
![Page 22: RoR 101: Session 1](https://reader033.vdocuments.site/reader033/viewer/2022051514/54bd178d4a7959ff308b4647/html5/thumbnails/22.jpg)
EVERYONE IS ENTITLED TO MY
OPINION
Convention over
Configuration
![Page 23: RoR 101: Session 1](https://reader033.vdocuments.site/reader033/viewer/2022051514/54bd178d4a7959ff308b4647/html5/thumbnails/23.jpg)
EVERYONE IS ENTITLED TO MY
OPINION
Convention over
Configuration(Not loved by all...)
![Page 24: RoR 101: Session 1](https://reader033.vdocuments.site/reader033/viewer/2022051514/54bd178d4a7959ff308b4647/html5/thumbnails/24.jpg)
How does it work?
In your app directory, navigate to: db/migrate/
rake db:migrate
![Page 25: RoR 101: Session 1](https://reader033.vdocuments.site/reader033/viewer/2022051514/54bd178d4a7959ff308b4647/html5/thumbnails/25.jpg)
The Station Migration
![Page 26: RoR 101: Session 1](https://reader033.vdocuments.site/reader033/viewer/2022051514/54bd178d4a7959ff308b4647/html5/thumbnails/26.jpg)
The Station Model
![Page 27: RoR 101: Session 1](https://reader033.vdocuments.site/reader033/viewer/2022051514/54bd178d4a7959ff308b4647/html5/thumbnails/27.jpg)
The Stations Controller
![Page 28: RoR 101: Session 1](https://reader033.vdocuments.site/reader033/viewer/2022051514/54bd178d4a7959ff308b4647/html5/thumbnails/28.jpg)
● Create – new, create
● Read – index, show
● Update – edit, update
● Destroy - destroy
CRUD actions in the controller
![Page 29: RoR 101: Session 1](https://reader033.vdocuments.site/reader033/viewer/2022051514/54bd178d4a7959ff308b4647/html5/thumbnails/29.jpg)
# GET /stations/1 # GET /stations/1.json def show @station = Station.find(params[:id])
respond_to do |format| format.html # show.html.erb format.json { render json: @station } end end
The 'Show' Action (Controller)
![Page 30: RoR 101: Session 1](https://reader033.vdocuments.site/reader033/viewer/2022051514/54bd178d4a7959ff308b4647/html5/thumbnails/30.jpg)
The 'Show' Action (View)
Action / View name convention