Slide 1

Slide 1 text

Modern webdevelopment with Ruby on Rails Robert Glaser Software Developer at Planetactive

Slide 2

Slide 2 text

Me • Studied at Fontys Venlo • 26 years • Software Developer at Planetactive - an Ogilvy Company in Düsseldorf twitter.com/mrreynolds

Slide 3

Slide 3 text

Planetactive • Ogilvy / WPP worldwide agency group • Full service digital marketing agency

Slide 4

Slide 4 text

So...

Slide 5

Slide 5 text

Modern? • What exactly does „modern“ mean? • „Modern“ is a very subjective and opinionated term • So is Ruby on Rails!

Slide 6

Slide 6 text

• Created in 2004 by David Heinemeier Hansson (DHH) at 37signals • Extracted from Basecamp (basecamphq.com) • Based on pragmatic solutions for common problems • Opinionated software • DRY - Don‘t Repeat Yourself

Slide 7

Slide 7 text

Wait. There are hundreds of MVC web frameworks!

Slide 8

Slide 8 text

„It‘s a very pragmatic, very targeted framework with a strong sense of direction. You might not share it‘s vision, but it undeniably has one.“ DHH photo copyright by James Duncan Davidson

Slide 9

Slide 9 text

Rails is „full stack“... • ActiveRecord (ORM) • ActionPack (ActionController, ActionView) • ActiveSupport (Class Extensions, Helpers) • ActionMailer • ActiveResource (REST Mapper) • Rails (Core Lib)

Slide 10

Slide 10 text

...with many ingredients • Instant start defaults • Webserver • Logger • Staging • AJAX • Webservices • Mail • Debugger • Caching • Strong REST support • Session Handling • Middleware (Rack) • Test Framework • Plugins • Engines • Clean MVC architecture • Scaffolding

Slide 11

Slide 11 text

ORM • Database abstraction & persistance ORM • ActiveRecord also a pattern • Migrations for incremental schema management

Slide 12

Slide 12 text

YEAH! I don‘t have to write SQL!!!

Slide 13

Slide 13 text

Yes, but you should understand what you are doing.

Slide 14

Slide 14 text

Convention over configuration • File naming conventions and assumptions • DB naming conventions for databases, tables, primary- and foreign keys • Pluralization and singularization through String inflectors • Per-Environment configuration files

Slide 15

Slide 15 text

DRY - Don‘t Repeat Yourself • Table column names don‘t need to be manually defined => read from DB • Reusing code (e.g. in views via partials) • Metaprogramming • DSLs

Slide 16

Slide 16 text

Model • Business logic • Data persistence • ActiveRecord

Slide 17

Slide 17 text

View • Data presentation • User Interaction • Template language ERB (Embedded Ruby) • ActionView

Slide 18

Slide 18 text

Controller • Event handling • Operation on models • Redirection and rendering • ActionController

Slide 19

Slide 19 text

ActionController ActiveRecord ActionView

Slide 20

Slide 20 text

ActiveRecord • Conventions (pluralized table names, ...) • Dynamic getters and setters • SQL mostly unnecessary • Entity relations (1:1, 1:n, n:n) • SQL injection protection • Validators • Callbacks

Slide 21

Slide 21 text

ActionView • ERB (Embedded Ruby) • Javascript generators (AJAX) • XML templates • Reusing template elements via partials and layouts

Slide 22

Slide 22 text

ActionController • Actions are public controller methods • Automatic template rendering • Multiple formats can easily be supported • RESTful model representations • Callbacks • Complete routing system • Security (CSRF, IP spoofing, etc.)

Slide 23

Slide 23 text

REST • Representational State Transfer • Representation of resources with only HTTP • Actions on resources defined by HTTP methods • Stateless • No additional transport layer like SOAP

Slide 24

Slide 24 text

REST

Slide 25

Slide 25 text

• Test environment & database • Fixtures or Factories, depending on you • Unit tests for models • Functional tests for controllers • Integration tests for workflow • Automated browser tests via Selenium Testing

Slide 26

Slide 26 text

Made for agile! • Test driven development encouraged • It‘s hard not to test • Coverage testing via rcov • Behaviour driven development with Rspec, Cucumber or Shoulda (Stories and contexts) • Iterative DB schema evolvement via migrations

Slide 27

Slide 27 text

Libraries, libraries!! • Plugins • Ruby Gems (Ruby‘s package management system)

Slide 28

Slide 28 text

So, what is Ruby?

Slide 29

Slide 29 text

• Released 1995 in Japan • Created by Yukihiro Matsumoto „Matz“ • Ruby should feel „natural, not simple“ • Ruby should be „more powerful than perl, more object-oriented than python“ Ruby

Slide 30

Slide 30 text

Everything is an object!

Slide 31

Slide 31 text

True open classes!

Slide 32

Slide 32 text

Loops Blocks erklären

Slide 33

Slide 33 text

Loops

Slide 34

Slide 34 text

Classes, objects, loops, iterators

Slide 35

Slide 35 text

Symbols

Slide 36

Slide 36 text

Symbols

Slide 37

Slide 37 text

Classes & modules

Slide 38

Slide 38 text

Mixins

Slide 39

Slide 39 text

Mixins

Slide 40

Slide 40 text

Metaprogramming

Slide 41

Slide 41 text

Exceptions

Slide 42

Slide 42 text

If you want to use Ruby, use it idiomaticly!

Slide 43

Slide 43 text

Demo time! 1) App erzeugen 2) Scaffold generieren 3) Resource generieren 4) Migration zeigen + ausführen 5) Fixtures 6) View zeigen 7) Controller zeigen 8) Model Methoden hinzufügen 9) Unit Test 10) REST erklären 11) named_scope

Slide 44

Slide 44 text

Fin! • Diploma thesis? • Practical semester? • Get in touch with me!