Ruby on Rails - A High-productivity Web Application Framework (June 2005)
Rails Framework
-
Upload
paultokarev -
Category
Technology
-
view
588 -
download
2
description
Transcript of Rails Framework
Ruby on Rails
B. Meyer, P. Tokarev
Web Technologies – Ruby on Rails – WS 2010/111
The slides are licensed under aCreative Commons Attribution 3.0 License
Content1. Introduction2. Main Concepts
1. MVC2. Convention over Configuration3. Generation of code
3. Movie Review Demo4. Additional Features
Web Technologies2
What is Ruby?Open‐source Programming Language
Platform independent
Object‐Oriented
Supports multiple paradigms e.g.
Functional Programming
Duck‐Typing
Metaprogramming
First Version (0.95) made public in Dec 1995
Web Technologies3
Some Ruby Paradigms: ObjectsIn Ruby everything is an object
Allows simple loops
For‐loop:
generates
Foreach‐loop:
generates
4 Web Technologies
Hello WorldHello World
2.times{puts “Hello World“}
array = [1, ‘hi‘, 3.14]array.each {|item| puts item }
1‘hi‘3.14
Some Ruby Paradigms: Duck‐TypingDuck‐Typing allows usage of class‐members only by knowing their name
5 Web Technologies
class Duck def description“A grey duck”enddef makeNoise“Quaak!“endend
class Cowdef description“A big cow”enddef makeNoise“Moo!“endend
def animalSound animalputs animal.description + “ makes “ + animal.makeNoiseend
“animalSound Duck.new” generates “A grey duck makes Quaak!”“animalSound Cow.new” generates “A big cow makes Moo!”
Some Ruby Paradigms: MetaprogrammingMetaprogramming allows code to write other code atruntime
Some possibilities:
Redefine classes and methods
Dynamically creating classes
Automatic object serialization
Modifying method calls
6 Web Technologies
What is Ruby on Rails?Open‐source Web Application Framework written in Ruby
It was published by David Heinemeyer Hanson
Rails was invented for an Application named „Basecamp“
Rails was first presented in 2004
Web Technologies7
HistoryVersion 1 was published on December 13th 2005
Version 2.0 was published on March 15th 2009Had more than a hundred improvements e.g.:
XML deserializationDebuggerPerformance improvements
Version 3.0 was published on August 29th 2010Merges merb with Rails → one big Ruby‐based Framework
Web Technologies8
PrinciplesRuby on Rails uses two main priciples:
Convention over Configuration
→ Easy to set up
Don‘t repeat yourself (DRY)
→ Rapid development
Web Technologies9Image:
Content1. Introduction2. Main Concepts
1. MVC2. Convention over Configuration3. Generation of code
3. Movie Review Demo4. Additional Features
Web Technologies10
MVC inside Rails
Web Technologies11
Controller
View Model
Client
Server
Dispatcher
ActionController
ActionView ActiveRecord
DBMS
requestforward
request
load
request
respond
redirect
render
querydata
display
Convention over Configuration
Web Technologies12
Modelmovie
Controllermovies_controller
show edit
Table in DBmovies
new
Model
Controller
View
Generation of codeRails command: rails generate scaffold movie
Table in databaseFolder and file structure for model, view and controllerCreates all 'CRUD' actions for controllerCreates all 'CRUD' views
1 line of code generates more then 100 lines of code
Web Technologies13
Content1. Introduction2. Main Concepts
1. MVC2. Convention over Configuration3. Generation of code
3. Movie Review Demo4. Additional Features
Web Technologies14
Movie Review DemoCreate Project
Web Technologies15
Movie Review DemoCreate ProjectUse scaffolding
Web Technologies16
Movie Review DemoCreate ProjectUse scaffoldingAdd new attributes to models
Web Technologies17
Movie Review DemoCreate ProjectUse scaffoldingAdd new attributes to modelsAdd new model
Web Technologies18
Movie Review DemoCreate ProjectUse scaffoldingAdd new attributes to modelsAdd new modelCreate one to many relation
Web Technologies19
Movie
id :inttitle :string...
Comment
id :inttext :textmovie_id :int
Content1. Introduction2. Main Concepts
1. MVC2. Convention over Configuration3. Generation of code
3. Movie Review Demo4. Additional Features
Web Technologies20
More featuresSession managementAvailable for different languages (e.g. Java)Various DB support
MySQL, Postgres, Oracle etc.Partials
Code that belongs to several documents DRYTests
Rails creates test files automaticallyLayouts
Customize look and feelPlug‐ins
Open‐source many Plug‐ins are availableWeb Technologies21
Implemented in Rails
Web Technologies22
SummaryRails is written in Ruby
Ruby != Rails
Open‐source
Web application framework
Convention over Configuration
Model‐View‐Controller (MVC)
Don’t repeat yourself (DRY)
Additional features available
23 Web Technologies