Top Banner
Rails 101
106

Rails 101

May 18, 2015

Download

Technology

Rob Cameron, Senor Software Engineer at The Active Network, walks us through the fundamentals of Ruby on Rails.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Rails 101

Rails 101

Page 2: Rails 101

Rails is an MVC framework for Ruby focused on building

web applications

Page 3: Rails 101

David Heinemeier Hansson (DHH)

Page 4: Rails 101

First open sourced July 2004

Page 5: Rails 101

Extracted from Basecamp

Page 6: Rails 101

Version 1.0December 13, 2005

Page 7: Rails 101
Page 8: Rails 101

August 2006

Apple announces that Rails will be

installed by default in OSX

Page 9: Rails 101

Version 2.0December 7, 2007

Version 3.0August 29, 2010

Page 10: Rails 101

Current Version3.0.10

Page 11: Rails 101

Conventionover

Configuration

Page 12: Rails 101

Model

Post

Page 13: Rails 101

Model

DB Table

Post

posts

Page 14: Rails 101

Model

DB Table

Controller

Post

posts

PostsController

Page 15: Rails 101

Model

DB Table

Controller

Index

Post

posts

PostsController

/postsposts_path

Page 16: Rails 101

Model

DB Table

Controller

Index

Show

Post

posts

PostsController

/postsposts_path

/posts/1post_path(@post)

Page 17: Rails 101

Model

DB Table

Controller

Index

Show

Edit

Post

posts

PostsController

/postsposts_path

/posts/1post_path(@post)

/posts/1/editedit_posts_path(@post)

Page 18: Rails 101

Posts table

Page 19: Rails 101

Primary KeyGenerated and managed by Rails

id

Posts table

Page 20: Rails 101

Primary KeyGenerated and managed by Rails

Foreign Keybelongs_to

id

user_id

Posts table

Page 21: Rails 101

Primary KeyGenerated and managed by Rails

Foreign Keybelongs_to

Auto-populatedtimestamps

id

user_id

created_at

updated_at

Posts table

Page 22: Rails 101

The client-side is important

Page 23: Rails 101

The client-side is important

PrototypeScriptaculous

Page 24: Rails 101

The client-side is important

PrototypeScriptaculous

jQuery

Page 25: Rails 101

Generators

Page 26: Rails 101

Create a new app

Page 27: Rails 101

Structure

Page 28: Rails 101
Page 29: Rails 101

Majority of code

Page 30: Rails 101

Majority of code

App/environment config

Page 31: Rails 101

Majority of code

App/environment config

Database config (and database!)

Page 32: Rails 101

Majority of code

App/environment config

Database config (and database!)

App documentation

Page 33: Rails 101

Majority of code

App/environment config

Database config (and database!)

App documentation

Custom code

Page 34: Rails 101

Majority of code

App/environment config

Database config (and database!)

App documentation

Custom code

Images, javascript, stylesheets

Page 35: Rails 101

Majority of code

App/environment config

Database config (and database!)

App documentation

Custom code

Images, javascript, stylesheets

Rails scripts

Page 36: Rails 101

Majority of code

App/environment config

Database config (and database!)

App documentation

Custom code

Images, javascript, stylesheets

Rails scripts

Test code

Page 37: Rails 101

Majority of code

App/environment config

Database config (and database!)

App documentation

Custom code

Images, javascript, stylesheets

Rails scripts

Test code

Third party code

Page 38: Rails 101

WEBrick

Page 39: Rails 101

Scaffolding

Page 40: Rails 101

Scaffolding

Creates CRUD screens for working with a single database

table

Page 41: Rails 101

Models

Page 42: Rails 101

ActiveRecord

Object Relational Mapping

Page 43: Rails 101

Database

Page 44: Rails 101

Migrations

Page 45: Rails 101

Relationships

Page 46: Rails 101

Rails console

Page 47: Rails 101

Validations

Page 48: Rails 101

Controllers

Page 49: Rails 101

Actions

Page 50: Rails 101

Routes

Page 51: Rails 101

params

Page 52: Rails 101

session

Page 53: Rails 101

@

Page 54: Rails 101

format

Page 55: Rails 101

“The essence of XML is this: the problem it solves is not hard, and it does not solve the problem well.”

— Phil Wadler

Page 56: Rails 101

Views

Page 57: Rails 101

Layouts

Page 58: Rails 101

Partials

Page 59: Rails 101

Form helpers

Page 60: Rails 101

Helpers

Page 61: Rails 101

html_safe

Page 62: Rails 101

RESTful

Page 63: Rails 101

Free web services

Page 64: Rails 101

ws-*

Page 65: Rails 101

“Don’t blame me, I’m just a contractor.”

Page 66: Rails 101

Let HTTP do what it was meant to do

Page 67: Rails 101

GETPOSTPUT

DELETE

Page 68: Rails 101

resources

Page 69: Rails 101

GET index /posts

Page 70: Rails 101

GET

GET

index

show

/posts

/posts/1

Page 71: Rails 101

GET

GET

GET

index

show

new

/posts

/posts/1

/posts/new

Page 72: Rails 101

GET

GET

GET

POST

index

show

new

create

/posts

/posts/1

/posts/new

/posts

Page 73: Rails 101

GET

GET

GET

POST

GET

index

show

new

create

edit

/posts

/posts/1

/posts/new

/posts

/posts/1/edit

Page 74: Rails 101

GET

GET

GET

POST

GETPUT

index

show

new

create

editupdate

/posts

/posts/1

/posts/new

/posts

/posts/1/edit/posts/1

Page 75: Rails 101

GET

GET

GET

POST

GETPUTDELETE

index

show

new

create

editupdatedestroy

/posts

/posts/1

/posts/new

/posts

/posts/1/edit/posts/1/posts/1

Page 76: Rails 101

Caching

Page 77: Rails 101

Fragment caching

Page 78: Rails 101

Action caching

Page 79: Rails 101

Page caching

Page 80: Rails 101

“There are only two hard problems in Computer Science: cache invalidation and naming things.”

— Phil Karlton

Page 81: Rails 101

Testing

Page 82: Rails 101

Unit

Page 83: Rails 101

Functional

Page 84: Rails 101

Integration

Page 85: Rails 101

Configuration

Page 86: Rails 101

Environments

Page 87: Rails 101

Deployment

Page 88: Rails 101
Page 89: Rails 101

Questions?

Page 90: Rails 101

Workshop

Page 91: Rails 101

Web interface to the Active.com Search API

Page 92: Rails 101

Example

Page 93: Rails 101

What you need to know

Page 94: Rails 101

Required Gems

Page 95: Rails 101

Required Gems

# Gemfile

gem 'httparty'gem 'heroku'

Page 96: Rails 101

Required Gems

# Gemfile

gem 'httparty'gem 'heroku'

rob$ bundle install

Page 97: Rails 101

Required Gems

# Gemfile

gem 'httparty'gem 'heroku'

rob$ bundle install

rob$ gem install bundler

Page 101: Rails 101

Iterate through array

my_array.each do |item| puts itemend

Page 103: Rails 101

Questions?

Page 104: Rails 101

# Gemfile

gem 'httparty'gem 'heroku'

rob$ bundle install

rob$ gem install bundler

http://api.amp.active.com/search? v=json& k=keywords& m=meta:channel%3DRunning& api_key=wuhmn9ye94xn3xnteudxsavw

JSON.parse(text)

HTTParty.get(url)

my_array.each do |item| puts itemend

git initgit add .git commit -m ‘First commit’heroku create...git push heroku master

Page 105: Rails 101

“Ruby on Rails will never be used in production at Active.”

Page 106: Rails 101

The End