RUBY ON RAILS

introduction and technical overview

Andy Wenk

Overview

  • PHILOSOPHY
  • ARCHITECTURE
  • KEY FEATURES
  • ROUTES
  • MVC
  • ENVIRONMENTS
  • ASSET PIPELINE
  • PRODUCTION SERVER
  • DEPLOYMENT
  • TESTING
  • EXTEND IT WITH RUBYGEMS
  • LINKS

PHILOSOPHY

  • Convention over Configuration
  • Don't Repeat Yourself
  • Fat models, skinny controllers
  • Rails is opinionated
  • Perl is not opinionated

Convention over Configuration

... means you’ll be productive. You won’t spend time setting up configuration files. You’ll spend less time thinking about where things go and what names to assign. And, because other developers have learned the same conventions, it is easier to collaborate.

Don't Repeat Yourself

... means that information is located in a single, unambiguous place. For example, using the ActiveRecord module of Rails, the developer does not need to specify database column names in class definitions. Instead, Ruby on Rails can retrieve this information from the database based on the class name.

Fat models, skinny controllers

... means that most of the application logic should be placed within the model while leaving the controller as light as possible.

Rails is opinionated

There is a "Rails way" for many of the problems that must be solved by a web application developer. If you follow the Rails conventions, you'll have fewer decisions to make and you'll find more of what you need is already built. The benefit is faster development, improved collaboration, and easier maintenance.

Perl is not opinionated

Perl is a prime example of "non-opinionated" software; there's no "right way" or "best way" to solve programming problems in Perl. Famously, Perl's documentation states, "In general, [Perl's built-in functions] do what you want, unless you want consistency."

ARCHITECTURE

Rails request lifecycle

KEY FEATURES

  • MVC
  • RESTful
  • support for many databases
  • development server
  • asset pipeline
  • mailer
  • HAML, ERB
  • CSS, SCSS, SASS
  • many, many helpers
  • Rack middleware

ROUTES

					        
Sumo::Application.routes.draw do
  root to: redirect('/start')

  match '/start', to: 'pages#home', as: 'home'
  match '/impressum', to: 'pages#imprint', as: 'imprint'
  
  post 'bestellung/bestellen', controller: 'checkout', action: 'place_order', as: 'checkout_place_order'
  get 'bestellung/bestaetigung', controller: 'checkout', action: 'confirm', as: 'checkout_confirm'

  resources :registration, path: 'registrierung'
  
  resources :cart, path: 'warenkorb' do
    member do
      get 'delete'
    end
  end
end
					        
					    

RESTful routes

Rails restful routes

MVC

Rails basic structure

ENVIRONMENTS

Rails environments

ASSET PIPELINE

Rails asset pipeline

Development Head

Rails development head

Development Foot

Rails development foot

Production Head

Rails production head

Production Foot

Rails production foot

PRODUCTION SERVER

  • Nginx with Passenger
  • Apache 2 with Passenger (aka mod_ruby)
  • Puma (best with jruby -> real multithreaded)
  • Unicorn (best with jruby -> real multithreaded)
  • Tomcat with jruby (war archive generated with warbler)
  • erm ... forget the previous option :)

DEPLOYMENT with Capistrano

Rails deployment with Capistrano

Capistrano commands

Rails deployment with Capistrano

TESTING

Oh yes we want to!

Capybara

Capybara

Cucumber - Features

Cucumber Features

Cucumber - Steps

Cucumber Steps

Rspec

Rspec

Extend it with Rubygems

Gemfile

Gemfile

Active Admin

Active Admin

Refinery CMS

Refinery CMS

No more pain in the ass with savon

Savon

LINKS

Ruby on Rails Guides
What is Ruby on Rails?
Ruby on Rails Architectural Design
Rails Rack
Railscasts
Railscast: Rails Metal (write Rack middleware) Railscast: Rails Middleware Walkthrough

Let's RockIt!

Thanx