50

RoR: What is it Good For?: Absolutely Something

Embed Size (px)

Citation preview

RoR: What is it Good For?

Absolutely Something

Ruby vs. Rails

Ruby Rails

Is it the Only Game in Town?

Is it the Only Game in Town?

If Rails is the Creature

▪ David Heinemeier Hansson (DHH)

▪ Drives racecars

▪ Created Rails for speed, self-reliance, and programmer happiness

▪ "If we don't have toys, we're just adults."

MVC Architecture

Architecture (n): the action or process of building; construction

What Does MVC Stand For Anyway?

M

V

C

What Does MVC Stand For Anyway?

Model

V

C

What Does MVC Stand For Anyway?

Model

View

C

What Does MVC Stand For Anyway?

Model

View

Controller

View

View

View

▪ What a user sees

▪ .ERB (embedded ruby) files as default – Mixes Ruby syntax with

HTML syntax in .html.erb files

But Wait, There’s More

▪ Rails provides a number of helpful additions to your views– Form helpers– URL helpers

▪ Partials – Templates that let you use

the same view section multiple places

– Especially useful for forms▪ _form.html.erb

Controller

▪ Where the action’s at

▪ Receives requests for the application

▪ Determines what information the view should display

▪ Sends commands to the model to change/update any data

▪ Ruby (.rb) file

Model

▪ Determines how data is stored and structured

▪ Less about the action, more about the inherent nature or state of the information

▪ Ruby (.rb) file

All About That (Data)base

Database Migrations

▪ Ruby classes that are designed to make it simple to create and modify database tables

▪ automatically generated when you generate a model– Can be generated

separately

▪ create the database tables when run

Relationships

▪ Declared in the models

▪ One to one– Users and social media profiles▪ A user only has_one Facebook profile, and that profile only belongs_to that user

▪ One to many– Users and orders▪ A user has_many orders, and each order only belongs_to that user

▪ Many to many– Writing prompts and categories▪ Categories can contain many prompts, and those prompts can belong to many

categories

– Join table prompt_categories– A prompt has_many :prompt_categories

has_many :categories, through: :prompt_categories– A prompt category belongs_to prompts AND categories

App Flow

View

Request

Router

Controller

Model

Database

App Flow

View

Request

Router

Controller

Model

Database

App Flow

View

Request

Router

Controller

Model

Database

App Flow

View

Request

Router

Controller

Model

Database

App Flow

View

Request

Router

Controller

Model

Database

App Flow

View

Request

Router

Controller

Model

Database

App Flow

View

Controller

Model

Database

App Flow

View

Controller

Model

Database

App Flow

View

Controller

Model

Database

App Flow

View

Controller

Model

Database

Gems

▪ Ruby recap:– Gems are packaged bits of

code other people have written

▪ Rails is a gem!

▪ People frequently use gems to:– Handle user authentication– Write tests for their code– Separate data chunks into

pages– Create fake data

▪ Gems go in your Gemfile

Who Uses Rails?

Is Rails Good for Everything?

Is Rails Good for Everything?

Katherine McClintic

Web Developer. Teacher. Musician. Fencer. Person who likes to take things

apart and usually puts them back together in working order-er.

@scarletalphabet

Rails Lead for Women Who Code DC meetup