rails framework
DESCRIPTION
TRANSCRIPT
![Page 1: Rails Framework](https://reader033.vdocument.in/reader033/viewer/2022051610/5495d715b47959962d8b5cc3/html5/thumbnails/1.jpg)
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
![Page 2: Rails Framework](https://reader033.vdocument.in/reader033/viewer/2022051610/5495d715b47959962d8b5cc3/html5/thumbnails/2.jpg)
Content1. Introduction2. Main Concepts
1. MVC2. Convention over Configuration3. Generation of code
3. Movie Review Demo4. Additional Features
Web Technologies2
![Page 3: Rails Framework](https://reader033.vdocument.in/reader033/viewer/2022051610/5495d715b47959962d8b5cc3/html5/thumbnails/3.jpg)
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
![Page 4: Rails Framework](https://reader033.vdocument.in/reader033/viewer/2022051610/5495d715b47959962d8b5cc3/html5/thumbnails/4.jpg)
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
![Page 5: Rails Framework](https://reader033.vdocument.in/reader033/viewer/2022051610/5495d715b47959962d8b5cc3/html5/thumbnails/5.jpg)
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!”
![Page 6: Rails Framework](https://reader033.vdocument.in/reader033/viewer/2022051610/5495d715b47959962d8b5cc3/html5/thumbnails/6.jpg)
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
![Page 7: Rails Framework](https://reader033.vdocument.in/reader033/viewer/2022051610/5495d715b47959962d8b5cc3/html5/thumbnails/7.jpg)
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
![Page 8: Rails Framework](https://reader033.vdocument.in/reader033/viewer/2022051610/5495d715b47959962d8b5cc3/html5/thumbnails/8.jpg)
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
![Page 9: Rails Framework](https://reader033.vdocument.in/reader033/viewer/2022051610/5495d715b47959962d8b5cc3/html5/thumbnails/9.jpg)
PrinciplesRuby on Rails uses two main priciples:
Convention over Configuration
→ Easy to set up
Don‘t repeat yourself (DRY)
→ Rapid development
Web Technologies9Image:
![Page 10: Rails Framework](https://reader033.vdocument.in/reader033/viewer/2022051610/5495d715b47959962d8b5cc3/html5/thumbnails/10.jpg)
Content1. Introduction2. Main Concepts
1. MVC2. Convention over Configuration3. Generation of code
3. Movie Review Demo4. Additional Features
Web Technologies10
![Page 11: Rails Framework](https://reader033.vdocument.in/reader033/viewer/2022051610/5495d715b47959962d8b5cc3/html5/thumbnails/11.jpg)
MVC inside Rails
Web Technologies11
Controller
View Model
Client
Server
Dispatcher
ActionController
ActionView ActiveRecord
DBMS
requestforward
request
load
request
respond
redirect
render
querydata
display
![Page 12: Rails Framework](https://reader033.vdocument.in/reader033/viewer/2022051610/5495d715b47959962d8b5cc3/html5/thumbnails/12.jpg)
Convention over Configuration
Web Technologies12
Modelmovie
Controllermovies_controller
show edit
Table in DBmovies
new
Model
Controller
View
![Page 13: Rails Framework](https://reader033.vdocument.in/reader033/viewer/2022051610/5495d715b47959962d8b5cc3/html5/thumbnails/13.jpg)
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
![Page 14: Rails Framework](https://reader033.vdocument.in/reader033/viewer/2022051610/5495d715b47959962d8b5cc3/html5/thumbnails/14.jpg)
Content1. Introduction2. Main Concepts
1. MVC2. Convention over Configuration3. Generation of code
3. Movie Review Demo4. Additional Features
Web Technologies14
![Page 15: Rails Framework](https://reader033.vdocument.in/reader033/viewer/2022051610/5495d715b47959962d8b5cc3/html5/thumbnails/15.jpg)
Movie Review DemoCreate Project
Web Technologies15
![Page 16: Rails Framework](https://reader033.vdocument.in/reader033/viewer/2022051610/5495d715b47959962d8b5cc3/html5/thumbnails/16.jpg)
Movie Review DemoCreate ProjectUse scaffolding
Web Technologies16
![Page 17: Rails Framework](https://reader033.vdocument.in/reader033/viewer/2022051610/5495d715b47959962d8b5cc3/html5/thumbnails/17.jpg)
Movie Review DemoCreate ProjectUse scaffoldingAdd new attributes to models
Web Technologies17
![Page 18: Rails Framework](https://reader033.vdocument.in/reader033/viewer/2022051610/5495d715b47959962d8b5cc3/html5/thumbnails/18.jpg)
Movie Review DemoCreate ProjectUse scaffoldingAdd new attributes to modelsAdd new model
Web Technologies18
![Page 19: Rails Framework](https://reader033.vdocument.in/reader033/viewer/2022051610/5495d715b47959962d8b5cc3/html5/thumbnails/19.jpg)
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
![Page 20: Rails Framework](https://reader033.vdocument.in/reader033/viewer/2022051610/5495d715b47959962d8b5cc3/html5/thumbnails/20.jpg)
Content1. Introduction2. Main Concepts
1. MVC2. Convention over Configuration3. Generation of code
3. Movie Review Demo4. Additional Features
Web Technologies20
![Page 21: Rails Framework](https://reader033.vdocument.in/reader033/viewer/2022051610/5495d715b47959962d8b5cc3/html5/thumbnails/21.jpg)
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
![Page 22: Rails Framework](https://reader033.vdocument.in/reader033/viewer/2022051610/5495d715b47959962d8b5cc3/html5/thumbnails/22.jpg)
Implemented in Rails
Web Technologies22
![Page 23: Rails Framework](https://reader033.vdocument.in/reader033/viewer/2022051610/5495d715b47959962d8b5cc3/html5/thumbnails/23.jpg)
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