Rails Girls: Programming, Web Applications and Ruby on Rails

66
Programming, Web Applications and Ruby on Rails Marco Schaden @donschado Saturday 24th May 2014

description

All the Buzzwords for the Workshop

Transcript of Rails Girls: Programming, Web Applications and Ruby on Rails

Page 1: Rails Girls: Programming, Web Applications and Ruby on Rails

Programming, !Web Applications !and Ruby on Rails

Marco Schaden!@donschado

Saturday 24th May 2014

Page 2: Rails Girls: Programming, Web Applications and Ruby on Rails

Buzzwords!

Web Application

RubyRails

Programming

HTTP

MVCModel

ViewContro

ller

Request

Response

ServerProtocol

?

?

?

?

?

?

?

HTML

all the stuff in 30 minutes

Page 3: Rails Girls: Programming, Web Applications and Ruby on Rails

<<Programming>>

Page 4: Rails Girls: Programming, Web Applications and Ruby on Rails
Page 5: Rails Girls: Programming, Web Applications and Ruby on Rails

"It’s a boy’s thing"

Page 6: Rails Girls: Programming, Web Applications and Ruby on Rails

http://en.wikipedia.org/wiki/Women_in_computing

Page 7: Rails Girls: Programming, Web Applications and Ruby on Rails

http://en.wikipedia.org/wiki/Women_in_computing

Page 8: Rails Girls: Programming, Web Applications and Ruby on Rails

"You need a Ph.D. in mathematics"

Page 9: Rails Girls: Programming, Web Applications and Ruby on Rails

Not necessarily, but…

communication: express your thoughts!and ideas properly

passion: care about what you’re doing !and be curious how things work

research: read documentation, !consult others or!just google it!

problem solving: read the error messages !and be hungry to solve issues

+ patience

Page 10: Rails Girls: Programming, Web Applications and Ruby on Rails
Page 11: Rails Girls: Programming, Web Applications and Ruby on Rails

programming: !!

is telling a computer what to do!!

(no magic involved)

Page 12: Rails Girls: Programming, Web Applications and Ruby on Rails

step-by-step instructions

= program

Page 13: Rails Girls: Programming, Web Applications and Ruby on Rails

3.times0do00 print0"Hello0World!"0end

Page 14: Rails Girls: Programming, Web Applications and Ruby on Rails

Ruby A PROGRAMMER’S BEST FRIEND

https://www.ruby-lang.org/

Page 15: Rails Girls: Programming, Web Applications and Ruby on Rails

imagine all the programming languages

Ruby

Page 16: Rails Girls: Programming, Web Applications and Ruby on Rails

Why Ruby?

Yukihiro Matsumoto !(Matz)

Ruby is designed to be human-oriented. It reduces the burden of programming. It tries to push jobs back to machines.!!You can accomplish more tasks with less work, in smaller yet readable code.

"Matz is nice so we are nice"

Page 17: Rails Girls: Programming, Web Applications and Ruby on Rails

Later we will learn more about Ruby…

Page 18: Rails Girls: Programming, Web Applications and Ruby on Rails

Web Application

?"A web application is a program that is displayed in a web browser. *Web applications are usually stored (and executed) on a web server.

They can be accessed through the Internet via a communication protocol such as HTTP. "

– Wikipedia

Page 19: Rails Girls: Programming, Web Applications and Ruby on Rails

HTTP?

Hyper Text Transfer Protocol

http://weheartit.com/entry/17157559

Page 20: Rails Girls: Programming, Web Applications and Ruby on Rails

HTTP Request Cycle In 4 Easy Steps

(or how the internet works)

Page 21: Rails Girls: Programming, Web Applications and Ruby on Rails

your computer!running a browser of your choice

a web server !somewhere on the internet!running a web application

Page 22: Rails Girls: Programming, Web Applications and Ruby on Rails

Hey$can$I$get$the$railsgirls$website?

1

http://railsgirls.com/cologne

Page 23: Rails Girls: Programming, Web Applications and Ruby on Rails

Hey$can$I$get$the$railsgirls$website?

http$request$get,$post,$put,$delete,…

1

Page 24: Rails Girls: Programming, Web Applications and Ruby on Rails

let$me$check…$.

2

Page 25: Rails Girls: Programming, Web Applications and Ruby on Rails

$ok,$here$it$is

http$response$generated$data,$HTML,$static$files,$images,…

3

Page 26: Rails Girls: Programming, Web Applications and Ruby on Rails

4

Yay!

Page 27: Rails Girls: Programming, Web Applications and Ruby on Rails

GOT IT!

Page 28: Rails Girls: Programming, Web Applications and Ruby on Rails
Page 29: Rails Girls: Programming, Web Applications and Ruby on Rails

David Heinemeier Hansson!(DHH)

Why Rails?

Rails is an attempt to mold the beauty and productiveness of Ruby into a framework for web applications.

Rails emphasizes principles such as:!• convention over configuration!• don't repeat yourself (DRY)!• model - view - controller

architecture (MVC)

http://contributors.rubyonrails.org/http://rubyonrails.org/

*over 3000 people have contributed:

Page 30: Rails Girls: Programming, Web Applications and Ruby on Rails

MVC?

Model - View - Controller

http://weheartit.com/entry/17157559

Page 31: Rails Girls: Programming, Web Applications and Ruby on Rails
Page 32: Rails Girls: Programming, Web Applications and Ruby on Rails

Data$+$Logic

Presentation

Intermediary

Page 33: Rails Girls: Programming, Web Applications and Ruby on Rails

WHY…?!?!

Page 34: Rails Girls: Programming, Web Applications and Ruby on Rails

w/o MVC:

http://media0.faz.net/ppmedia/aktuell/wirtschaft/777415979/1.1528426/default/wo-ist-noch-mal-die-rechnung-ein-buero-mit-sehr-kreativem-chaos.jpg

Page 35: Rails Girls: Programming, Web Applications and Ruby on Rails

with MVC:

http://blog.meine-moebelmanufaktur.de/wp-content/uploads/2014/02/bunte_ordner_buero.jpg

Page 36: Rails Girls: Programming, Web Applications and Ruby on Rails

/

Example MVC Web Application

https://github.com/DonSchado/facebook-lite

Page 37: Rails Girls: Programming, Web Applications and Ruby on Rails

/

Example MVC Web Application

Layout

View

Post

https://github.com/DonSchado/facebook-lite

Page 38: Rails Girls: Programming, Web Applications and Ruby on Rails

URL localhost:3000/

(remember the request cycle?)

Page 39: Rails Girls: Programming, Web Applications and Ruby on Rails

GET /!Request

Page 40: Rails Girls: Programming, Web Applications and Ruby on Rails

Router get "/" => "welcome#index"!

Page 41: Rails Girls: Programming, Web Applications and Ruby on Rails

Controller class WelcomeController < ApplicationController! def index!

$$@posts0= Post.all ! end!end!

Page 42: Rails Girls: Programming, Web Applications and Ruby on Rails

Model class Post < ActiveRecord::Base!end!

Page 43: Rails Girls: Programming, Web Applications and Ruby on Rails

Database * create_table "posts" do |t|!  t.text "content"!  t.integer "user_id"!  t.datetime "created_at"!  t.datetime "updated_at"!end!

Page 44: Rails Girls: Programming, Web Applications and Ruby on Rails

Model class Post < ActiveRecord::Base!end!

Page 45: Rails Girls: Programming, Web Applications and Ruby on Rails

Controller class WelcomeController < ApplicationController! def index!

$$@posts0= Post.all ! end!end!

Page 46: Rails Girls: Programming, Web Applications and Ruby on Rails

View <h1>Das neuste aus ...$</h1>!!<ul>$$$<%[email protected]$do$|post|$%>0!!!!!00<%0end0%>$</ul>$

<li>$

$$<%=$image_tag(post.user.avatar)$%>$$$<%=$post.user.name$%>$$$<%=$post.content$%>$</li>

Page 47: Rails Girls: Programming, Web Applications and Ruby on Rails

<html$lang="en">$

$$<head>$

$$$$$<title>Facebook$Lite</title>$

$$$$$<%=$stylesheet_link_tag$$$$"application",$media:$"all"$%>$$$$$$<%=$javascript_include_tag$"application"$%>$$$</head>$

$$<body>$

$$$$<div$class="container">$

$$$$$$<%=$yield$%>$$$$$</div>$

$$</body>$

</html>

Layout

Page 48: Rails Girls: Programming, Web Applications and Ruby on Rails

Response (HTML)*

<html lang="en">! <head>! <title>Facebook Lite</title>! <link href="/assets/application.css" media="all" rel="stylesheet">! <script src="/assets/application.js"></script>! </head>! <body>! <div>! <h1>Das Neuste aus dem ganzen Netzwerk</h1>! <ul>! <li>! <img src="https://somewhere.github.com/1062e0f.png">! <h4>Liane<small>19 Nov 20:32</small></h4>! <p>Ich bin hier!!!</p>! </li>! <li>! <img src="https://somwhere.github.com/fa47a113f69.png">! <h4>Marco<small>19 Nov 20:02</small></h4>! <p>Hallo, ist da wer?</p>! </li>! <li>! <img src="https://somwhere.github.com/fa47a113f69.png">! <h4>Marco<small>19 Nov 19:02</small></h4>! <p>Hallo Welt!</p>! </li>! </ul>! </div>! </body>!</html>

Page 49: Rails Girls: Programming, Web Applications and Ruby on Rails

URL localhost:3000/

Page 50: Rails Girls: Programming, Web Applications and Ruby on Rails

http://cheezburger.com/

Page 51: Rails Girls: Programming, Web Applications and Ruby on Rails

Response (HTML)

Browser

Layout

View

Request

Router

Controller

Model

Database

Page 52: Rails Girls: Programming, Web Applications and Ruby on Rails

Response (HTML)

Browser

Layout

View

Request

Router

Controller

Model

Database

Page 53: Rails Girls: Programming, Web Applications and Ruby on Rails

Response (HTML)

Browser

Layout

View

Request

Router

Controller

Model

Database

Page 54: Rails Girls: Programming, Web Applications and Ruby on Rails

Response (HTML)

Browser

Layout

View

Request

Router

Controller

Model

Database

Page 55: Rails Girls: Programming, Web Applications and Ruby on Rails

Response (HTML)

Browser

Layout

View

Request

Router

Controller

Model

Database

Page 56: Rails Girls: Programming, Web Applications and Ruby on Rails

Response (HTML)

Browser

Layout

View

Request

Router

Controller

Model

Database

Page 57: Rails Girls: Programming, Web Applications and Ruby on Rails

Response (HTML)

Browser

Layout

View

Request

Router

Controller

Model

Database

Page 58: Rails Girls: Programming, Web Applications and Ruby on Rails

Response (HTML)

Browser

Layout

View

Request

Router

Controller

Model

Database

Page 59: Rails Girls: Programming, Web Applications and Ruby on Rails

Response (HTML)

Browser

Layout

View

Request

Router

Controller

Model

Database

Page 60: Rails Girls: Programming, Web Applications and Ruby on Rails

Response (HTML)

Browser

Layout

View

Request

Router

Controller

Model

Database

Page 61: Rails Girls: Programming, Web Applications and Ruby on Rails

Response (HTML)

Browser

Layout

View

Request

Router

Controller

Model

Database

Page 62: Rails Girls: Programming, Web Applications and Ruby on Rails

Response (HTML)

Browser

Layout

View

Request

Router

Controller

Model

Database

Page 63: Rails Girls: Programming, Web Applications and Ruby on Rails

All The Tools You Need:

A Text Editor for writing code and editing files.

The Terminal (known as Command Prompt)!Where you start the rails server and run commands.

A Web Browser (Firefox, Safari, Chrome,…) for viewing and interacting with your application.

Ruby, the amazing programming language we love

Rails, the framework for building web applications

Page 64: Rails Girls: Programming, Web Applications and Ruby on Rails

Conclusionwe’ve learned a lot of new stuff

Page 65: Rails Girls: Programming, Web Applications and Ruby on Rails

http$response$generated$data,$HTML,$static$files,$images,…

http$request$get,$post,$put,$delete,…

Page 66: Rails Girls: Programming, Web Applications and Ruby on Rails

Have fun!!

Enjoy your workshop!!

Ask the coaches!

http://tryruby.orgNow let’s start coding!

1

http://guides.railsgirls.com/app2