83
Introduction to Web Applications Tobias Pfeiffer @PragTob pragtob.wordpress.com

Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

Introduction to Web Applications

Tobias Pfeiffer@PragTob

pragtob.wordpress.com

Page 2: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

Today

Page 3: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating
Page 4: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

What is a web application?

Page 5: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

Not rocket science

Page 6: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

I am Rails (and So Can You!)

Page 7: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

Programming is fun!

Page 8: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

What you are goingto build today

Page 9: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

So what is a web application?

Page 10: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

Presented in aweb browser

Page 11: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

Runs on a server...

Page 12: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

...or the cloud

Page 13: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

is dynamic

Page 14: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

A high level overview

Page 15: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

High level overview

Page 16: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

High level overview

Page 17: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

High level overview

Request

Page 18: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

High level overview

Page 19: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

High level overview

Answer

Page 20: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

High level overview

Answer

Page 21: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

High level overview

Page 22: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

What parts does a web application consist of?

Page 23: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

Web Application

Page 24: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

Front End

Back End

Page 25: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

Front End

Back End

Page 26: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

CSS

HTML

JavaScript

Page 27: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

Structure and content

Page 28: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

CSS

HTML

JavaScript

Page 29: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

Styling to transform...

Page 30: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

...this...

Page 31: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

...into this.

Page 32: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

CSS

HTML

JavaScript

Page 33: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

Back End

CSS

HTML

JavaScript

Page 34: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

Back End

CSS

HTML

JavaScript

Page 35: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

Logic

Infrastructure

Page 36: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

Logic

Infrastructure

Page 37: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

Logic

● Behaviour● Implements the business logic● Ties all the parts together● Generates content

Page 38: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

Ruby on Rails

Page 39: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

Logic

Infrastructure

Page 40: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

Web Server

Page 41: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

Logic

Infrastructure

Page 42: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

Storing all yourdata...

Page 43: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

...in giant tables

Page 44: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

Recap

Page 45: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

Logic

Storage

Infrastructure

CSS

HTML

JavaScript

Web Application Landscape

Page 46: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

Logic

Storage

Infrastructure

CSS

HTML

JavaScript

Web Application Landscape

Bootstrap

XML DOM

jQuery

Ruby on Rails

Sqlite

Apache

WEBrick

MongoD

B

Thin

RubyPHP

Python

Django

Page 47: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

But what is Ruby on Rails?

Page 48: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

A web application framework written in Ruby

Page 49: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

● A general purpose programming language

● Principle of least surprise● Invented by Yukihiro Matsumoto

Page 50: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

"I hope to see Ruby help every programmer in the world to be productive, and to enjoy programming, and to be happy. That is the primary purpose of Ruby language."Yukihiro Matsumoto

Page 51: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

Ruby on Rails

● Framework written in Ruby● set of functionality to help write web

applications– Connecting to the database (ActiveRecord)– Generating HTML (ERB)– Pays attention to security– … and so much more!

● Model View Controller● You write in Ruby

Page 52: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

Let's get into some Ruby

Page 53: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

But before that...

Page 54: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

Cookies & Questions

Page 55: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

Open a terminal/console

Page 56: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

irb

Page 57: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

tobi@speedy:~$ irb1.9.3p194 :001 >

Page 58: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

irb – interactive ruby

● talking to ruby● You tell ruby something● Ruby responds with what it understood● Coaches are going to help you!

Page 59: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

1.9.3p194 :001 > 5 => 5

Page 60: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

1.9.3p194 :002 > 5 + 3 => 8

Page 61: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

1.9.3p194 :003 > 8 * 7 => 56

Page 62: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

1.9.3p194 :004 > "Tobias Pfeiffer" => "Tobias Pfeiffer"

Page 63: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

1.9.3p194 :005 > name = "Tobi" => "Tobi"

Page 64: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

1.9.3p194 :006 > name => "Tobi"

Page 65: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

1.9.3p194 :007 > result = 8 * 7 => 56

Page 66: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

1.9.3p194 :008 > result * 10 => 560

Page 67: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

1.9.3p194 :009 > name + " likes Sweden" => "Tobi likes Sweden"

Page 68: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

1.9.3p194 :010 > puts "Hello World!"Hello World! => nil

Page 69: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

1.9.3p194 :011 > fruits = ["apple", "keewee", "orange"] => ["apple", "keewee", "orange"]

Page 70: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

1.9.3p194 :013 > fruits.each do |fruit| puts fruit endapplekeeweeorange => ["apple", "keewee", "orange"]

Page 71: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

1.9.3p194 :014 > fruits[0] => "apple"

Page 72: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

1.9.3p194 :015 > symbol = :wuh => :wuh 1.9.3p194 :016 > symbol => :wuh

Page 73: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

1.9.3p194 :017 > dictionary = {:hi => "Hej", :good => "bra", :cookie => "kaka"} => {:hi=>"Hej", :good=>"bra", :cookie=>"kaka"} 1.9.3p194 :018 > dictionary[:hi] => "Hej" 1.9.3p194 :019 > dictionary[:cookie] => "kaka"

Page 74: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

1.9.3p194 :020 > def hello1.9.3p194 :021?> puts "Hello there!"1.9.3p194 :022?> end => nil

Page 75: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

1.9.3p194 :026 > helloHello there! => nil

Page 76: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

1.9.3p194 :023 > def greeter(person)1.9.3p194 :024?> puts "Hello " + person1.9.3p194 :025?> end => nil

Page 77: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

1.9.3p194 :027 > greeter("Fanny")Hello Fanny => nil

Page 78: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

1.9.3p194 :028 > greeterArgumentError: wrong number of arguments (0 for 1)

from (irb):23:in `greeter'from (irb):28from /home/tobi/.rvm/rubies/ruby-1.9.3-

p194/bin/irb:16:in `<main>'

Page 79: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

1.9.3p194 :029 > class Person1.9.3p194 :030?> attr_accessor :name, :age1.9.3p194 :031?> end => nil 1.9.3p194 :032 > tobi = Person.new => #<Person:0x0000000205f080>

Page 80: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

1.9.3p194 :033 > tobi.name => nil 1.9.3p194 :034 > tobi.name = "Tobi" => "Tobi" 1.9.3p194 :035 > tobi.age = 23 => 23 1.9.3p194 :036 > tobi.name => "Tobi" 1.9.3p194 :037 > tobi.age => 23

Page 81: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

1.9.3p194 :038 > tobi.age * 365 => 8395 1.9.3p194 :039 > puts "This was a talk by " + tobi.name + " - thank you!"This was a talk by Tobi - thank you! => nil

Page 82: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

Thank you and enjoy coding!

Tobias Pfeiffer@PragTob

pragtob.wordpress.comlisten to me talking about learning Ruby (German)

Page 83: Introduction to Web Applications...Ruby on Rails Framework written in Ruby set of functionality to help write web applications – Connecting to the database (ActiveRecord) – Generating

Photo credit● http://www.flickr.com/photos/captainkimo/5918836159/

● http://www.flickr.com/photos/weppos/7486411688/

● http://www.flickr.com/photos/railsgirlsberlin/7882839698/in/photostream

● http://www.flickr.com/photos/nirak/644336486/