RoR 101: Session 1

Preview:

DESCRIPTION

Part 1 of 6

Citation preview

Building Web Apps with Rails

Hello

What about you?

The Course

Hello Ruby!

Hello Rails

Try Ruby!

Http://tryruby.org

Stop when you see "summary 4" or stuff

about file operations.

Skip to challenge on Classes.

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

A Ruby Class

Our app: FirstFM

FirstFM

StationsUsers StationLists

FirstFM

StationsUsers StationLists

Let's get going

rails new firstfm

rails generate scaffold Station name:string description:text url:string

cd firstfm

rake db:migrate

rails server

What? How did this happen?

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 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

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

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

EVERYONE IS ENTITLED TO MY

OPINION

EVERYONE IS ENTITLED TO MY

OPINION

Convention over

Configuration

EVERYONE IS ENTITLED TO MY

OPINION

Convention over

Configuration(Not loved by all...)

How does it work?

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

rake db:migrate

The Station Migration

The Station Model

The Stations Controller

● Create – new, create

● Read – index, show

● Update – edit, update

● Destroy - destroy

CRUD actions in the controller

# 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)

The 'Show' Action (View)

Action / View name convention