Download pdf - RoR 101: Session 1

Transcript
Page 1: RoR 101: Session 1

Building Web Apps with Rails

Page 2: RoR 101: Session 1

Hello

Page 3: RoR 101: Session 1
Page 4: RoR 101: Session 1
Page 5: RoR 101: Session 1
Page 6: RoR 101: Session 1

What about you?

Page 7: RoR 101: Session 1

The Course

Page 8: RoR 101: Session 1

Hello Ruby!

Hello Rails

Page 9: RoR 101: Session 1

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

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

A Ruby Class

Page 12: RoR 101: Session 1

Our app: FirstFM

Page 13: RoR 101: Session 1

FirstFM

StationsUsers StationLists

Page 14: RoR 101: Session 1

FirstFM

StationsUsers StationLists

Page 15: RoR 101: Session 1

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

What? How did this happen?

Page 17: RoR 101: Session 1

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

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

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

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

EVERYONE IS ENTITLED TO MY

OPINION

Page 22: RoR 101: Session 1

EVERYONE IS ENTITLED TO MY

OPINION

Convention over

Configuration

Page 23: RoR 101: Session 1

EVERYONE IS ENTITLED TO MY

OPINION

Convention over

Configuration(Not loved by all...)

Page 24: RoR 101: Session 1

How does it work?

In your app directory, navigate to: db/migrate/

rake db:migrate

Page 25: RoR 101: Session 1

The Station Migration

Page 26: RoR 101: Session 1

The Station Model

Page 27: RoR 101: Session 1

The Stations Controller

Page 28: RoR 101: Session 1

● Create – new, create

● Read – index, show

● Update – edit, update

● Destroy - destroy

CRUD actions in the controller

Page 29: RoR 101: Session 1

# 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

The 'Show' Action (View)

Action / View name convention