SlideShare a Scribd company logo
Ruby on RailsServer-side web development VladStoianVictor Porof
What we’ll talk aboutWhat is Ruby on Rails?A brief historyMVC architecture in a nutshellDistinctive framework featuresWhy Ruby? Why Rails?Demo
What is RoR?Open SourceAbstraction providing generic server-side functionalityUsed for web application developmentIt’s a framework for the Ruby language..so don’t confuse it with plain Ruby!
A brief historyOriginates in David Heinemeier Hansson’s workFirst released in July 2004Apple ships RoR with Mac OS X Leopard since 2007Major new developments with v2.3 in 2009TemplatesGenerate skeleton applicationsCustom gems and configurationsLatest: v3.0.5, 27 February 2011
MVC architectureRoR is based on the Model-View-Controller designIt’s an architectural development patternWidely used in many other frameworks:Oracle Application Framework, Cocoon, JSF (Java)ASP.NET (C#)SproutCore, JavascriptMVC (Javascript)Django, Pylons (Python)CakePHP(PHP)PureMVC (many languages)
Server-side Web development via Ruby on Rails
MVC on RailsModels are Ruby classes, used to store and validate dataHandles migrationsThey talk to databasesMySQLSQLitePostgreSQLNoSQLMongoDBCassandra“Chubby guy in the back room” crunching the numbers
Model snippetclass Person < ActiveRecord::Basevalidates_presence_of :namehas_many :wifesendPerson.create(:name => ”Muhammad Ali”).valid? # => truePerson.create(:name => nil).valid? # => false
Migration snippetclass AddReceiveNewsletterToUsers < ActiveRecord::Migrationdefself.upchange_table :users do |t|t.boolean :receive_newsletter, :default => false    endUser.update_all ["receive_newsletter = ?", true]  enddefself.downremove_column :users, :receive_newsletter  endend
MVC on RailsWhat the user seesHTML, CSS, XML, Javascript (jQuery)JSON, RSS, AtomAutomatically generated “view-puppets”Visual representation of dataDoes not have direct access to the model!It shouldn’t do lots of processing or calculation
View snippet <!-- app/views/items/new.rhtml -->  <%= form_tag :action => “create” %>   Name: <%= text_field“item”, “name”%><br/>Email: <%= text_field“item”, ”email”%><br/>  Password: <%= hidden_field “item”, “password”%><br/>   <%= submit_tag %>  <%= end_form_tag %>
MVC on RailsGateway between the model and the viewHandles user requestsDoes parsing and data submissionsTakes care of sessions, cookiesWorks out what data to show and what views to render”The best controller: it gives orders without knowing  (or caring) how it gets done”
Controller snippetclassItemsController < ApplicationController    def edit      @item = Item.find(params[:id])ifrequest.post?         @item.update_attributes(params[:item])redirect_to :action => 'edit', :id => @item.id      end    end  end
MVC on RailsTo summarize:Keep your view code skinnyKeep your controller code skinnyThe fatness is in the model
Distinctive framework featuresCode generatorsAwesome built-in functions => rapid developmentTons of “gems” to choose fromCross-platform compatibilityAutomated operation (CRUD)Create, Retrieve, Automate and DeleteSimplified testing (Rake script)
Code generator snippet#model generator (general)ruby script/generate model model_name #(in v2.3)rails generate model model_name #(in v3)#model generator (example)rails generate model user name:stringhashed_password:string#controller generator (general)ruby script/generate controller controller_namemethod_name(s)  (in v2.3)rails generate controller controller_namemethod_name(s) (in v3)#controller generator (example)rails generate controller store index
RoR serversMongrelWebbrickThinApache (mod_passanger)..so it’s very scalable!
Famous projects on RailsTwitter (microblogging)Crunchbase (companies database)BaseCamp (project management)Hulu (online tv)Yellowpages.com (phone database)Xing (business network)
Why Ruby?Interpreted language => greater flexibilityProvides JIT (just in time compilation)Garbage collectionAble to generate code on the flyCleaner syntax (no more “Verbose verbose is too verbose for verbose”)Many implementations:Jruby, IronRuby, Rubinius(Ruby + C++), MacRuby (ObjC)
Why Rails?Based on RubyEasy to implement CGI scriptsRapid web-application developmentDesigned to make programming work easierLess coding, more functionalityThousands of pluginsDon’t reinvent the wheel
Server-side Web development via Ruby on Rails
Creating a blog with
Server-side Web development via Ruby on Rails
Server-side Web development via Ruby on Rails
Ad

Recommended

Rishabh Technology and Tools Overview (1)
Rishabh Technology and Tools Overview (1)
D Trivedi
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVC
Sirwan Afifi
 
Valentine with Angular js - Introduction
Valentine with Angular js - Introduction
Senthil Kumar
 
MVC 1.0 als alternative Webtechnologie
MVC 1.0 als alternative Webtechnologie
OPEN KNOWLEDGE GmbH
 
ASP.NET Identity - O Novo componente de Membership do ASP.NET
ASP.NET Identity - O Novo componente de Membership do ASP.NET
Eduardo Pires
 
Introduction to Ember.js
Introduction to Ember.js
Mike Nicholaides
 
Asp.net core 1.0 (Peter Himschoot)
Asp.net core 1.0 (Peter Himschoot)
Visug
 
Combining HTML5 with MVC framework to simplify realtime collaboration for we...
Combining HTML5 with MVC framework to simplify realtime collaboration for we...
Gopikrishnan Sasikumar
 
Angular 4
Angular 4
Saurabh Juneja
 
TDD with ASP.NET MVC 1.0
TDD with ASP.NET MVC 1.0
Shiju Varghese
 
Require.JS
Require.JS
Ivano Malavolta
 
Asp.net c# MVC-5 Training-Day-1 of Day-9
Asp.net c# MVC-5 Training-Day-1 of Day-9
AHM Pervej Kabir
 
Single Page Apps
Single Page Apps
Gil Fink
 
Modern Applications With Asp.net Core 5 and Vue JS 3
Modern Applications With Asp.net Core 5 and Vue JS 3
Alexandre Malavasi
 
Top java script frameworks ppt
Top java script frameworks ppt
Omkarsoft Bangalore
 
Zend MVC pattern based Framework – Best for Enterprise web applications
Zend MVC pattern based Framework – Best for Enterprise web applications
Etisbew Technology Group
 
REPORT ON ASP.NET
REPORT ON ASP.NET
LOKESH
 
Code igniter overview
Code igniter overview
umesh patil
 
Swagger - Making REST APIs friendlier
Swagger - Making REST APIs friendlier
Miroslav Resetar
 
Entity Framework Core 1.0
Entity Framework Core 1.0
Senthil Kumar
 
What’s New and Hot in .NET 4.0
What’s New and Hot in .NET 4.0
Jess Chadwick
 
Angular js presentation at Datacom
Angular js presentation at Datacom
David Xi Peng Yang
 
Intro to Ruby on Rails
Intro to Ruby on Rails
Mark Menard
 
Ruby on Rails: Building Web Applications Is Fun Again!
Ruby on Rails: Building Web Applications Is Fun Again!
judofyr
 
Building Web Applications with Zend Framework
Building Web Applications with Zend Framework
Phil Brown
 
PLAT-8 Spring Web Scripts and Spring Surf
PLAT-8 Spring Web Scripts and Spring Surf
Alfresco Software
 
Manasa
Manasa
ManasaRamanarayan
 
Kick start your journey as mern stack developer
Kick start your journey as mern stack developer
ShrutiPanjwani1
 
[TW] CSS Files Optimization
[TW] CSS Files Optimization
Bogdan Gaza
 
Web Development With Ruby - From Simple To Complex
Web Development With Ruby - From Simple To Complex
Brian Hogan
 

More Related Content

What's hot (20)

Angular 4
Angular 4
Saurabh Juneja
 
TDD with ASP.NET MVC 1.0
TDD with ASP.NET MVC 1.0
Shiju Varghese
 
Require.JS
Require.JS
Ivano Malavolta
 
Asp.net c# MVC-5 Training-Day-1 of Day-9
Asp.net c# MVC-5 Training-Day-1 of Day-9
AHM Pervej Kabir
 
Single Page Apps
Single Page Apps
Gil Fink
 
Modern Applications With Asp.net Core 5 and Vue JS 3
Modern Applications With Asp.net Core 5 and Vue JS 3
Alexandre Malavasi
 
Top java script frameworks ppt
Top java script frameworks ppt
Omkarsoft Bangalore
 
Zend MVC pattern based Framework – Best for Enterprise web applications
Zend MVC pattern based Framework – Best for Enterprise web applications
Etisbew Technology Group
 
REPORT ON ASP.NET
REPORT ON ASP.NET
LOKESH
 
Code igniter overview
Code igniter overview
umesh patil
 
Swagger - Making REST APIs friendlier
Swagger - Making REST APIs friendlier
Miroslav Resetar
 
Entity Framework Core 1.0
Entity Framework Core 1.0
Senthil Kumar
 
What’s New and Hot in .NET 4.0
What’s New and Hot in .NET 4.0
Jess Chadwick
 
Angular js presentation at Datacom
Angular js presentation at Datacom
David Xi Peng Yang
 
Intro to Ruby on Rails
Intro to Ruby on Rails
Mark Menard
 
Ruby on Rails: Building Web Applications Is Fun Again!
Ruby on Rails: Building Web Applications Is Fun Again!
judofyr
 
Building Web Applications with Zend Framework
Building Web Applications with Zend Framework
Phil Brown
 
PLAT-8 Spring Web Scripts and Spring Surf
PLAT-8 Spring Web Scripts and Spring Surf
Alfresco Software
 
Manasa
Manasa
ManasaRamanarayan
 
Kick start your journey as mern stack developer
Kick start your journey as mern stack developer
ShrutiPanjwani1
 
TDD with ASP.NET MVC 1.0
TDD with ASP.NET MVC 1.0
Shiju Varghese
 
Asp.net c# MVC-5 Training-Day-1 of Day-9
Asp.net c# MVC-5 Training-Day-1 of Day-9
AHM Pervej Kabir
 
Single Page Apps
Single Page Apps
Gil Fink
 
Modern Applications With Asp.net Core 5 and Vue JS 3
Modern Applications With Asp.net Core 5 and Vue JS 3
Alexandre Malavasi
 
Zend MVC pattern based Framework – Best for Enterprise web applications
Zend MVC pattern based Framework – Best for Enterprise web applications
Etisbew Technology Group
 
REPORT ON ASP.NET
REPORT ON ASP.NET
LOKESH
 
Code igniter overview
Code igniter overview
umesh patil
 
Swagger - Making REST APIs friendlier
Swagger - Making REST APIs friendlier
Miroslav Resetar
 
Entity Framework Core 1.0
Entity Framework Core 1.0
Senthil Kumar
 
What’s New and Hot in .NET 4.0
What’s New and Hot in .NET 4.0
Jess Chadwick
 
Angular js presentation at Datacom
Angular js presentation at Datacom
David Xi Peng Yang
 
Intro to Ruby on Rails
Intro to Ruby on Rails
Mark Menard
 
Ruby on Rails: Building Web Applications Is Fun Again!
Ruby on Rails: Building Web Applications Is Fun Again!
judofyr
 
Building Web Applications with Zend Framework
Building Web Applications with Zend Framework
Phil Brown
 
PLAT-8 Spring Web Scripts and Spring Surf
PLAT-8 Spring Web Scripts and Spring Surf
Alfresco Software
 
Kick start your journey as mern stack developer
Kick start your journey as mern stack developer
ShrutiPanjwani1
 

Viewers also liked (7)

[TW] CSS Files Optimization
[TW] CSS Files Optimization
Bogdan Gaza
 
Web Development With Ruby - From Simple To Complex
Web Development With Ruby - From Simple To Complex
Brian Hogan
 
Using Ruby on Rails with legacy Oracle databases
Using Ruby on Rails with legacy Oracle databases
Raimonds Simanovskis
 
Fast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on Oracle
Raimonds Simanovskis
 
External Data Access with jQuery
External Data Access with jQuery
Doncho Minkov
 
Railsチュートリアルの歩き方 (第4版)
Railsチュートリアルの歩き方 (第4版)
Yohei Yasukawa
 
JSON and REST
JSON and REST
Robert MacLean
 
[TW] CSS Files Optimization
[TW] CSS Files Optimization
Bogdan Gaza
 
Web Development With Ruby - From Simple To Complex
Web Development With Ruby - From Simple To Complex
Brian Hogan
 
Using Ruby on Rails with legacy Oracle databases
Using Ruby on Rails with legacy Oracle databases
Raimonds Simanovskis
 
Fast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on Oracle
Raimonds Simanovskis
 
External Data Access with jQuery
External Data Access with jQuery
Doncho Minkov
 
Railsチュートリアルの歩き方 (第4版)
Railsチュートリアルの歩き方 (第4版)
Yohei Yasukawa
 
Ad

Similar to Server-side Web development via Ruby on Rails (20)

Beginners' guide to Ruby on Rails
Beginners' guide to Ruby on Rails
Victor Porof
 
Ruby On Rails
Ruby On Rails
Gautam Rege
 
Ruby Rails Web Development
Ruby Rails Web Development
Sonia Simi
 
Ruby On Rails
Ruby On Rails
Balint Erdi
 
Aspose pdf
Aspose pdf
Jim Jones
 
Ruby On Rails Basics
Ruby On Rails Basics
Amit Solanki
 
A Tour of Ruby On Rails
A Tour of Ruby On Rails
David Keener
 
RubyOnRails
RubyOnRails
artfulgeek
 
Ruby On Rails Seminar Basis Softexpo Feb2010
Ruby On Rails Seminar Basis Softexpo Feb2010
arif44
 
Ruby On Rails
Ruby On Rails
anides
 
Introduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman Ortega
arman o
 
Rubyonrails 090715105949-phpapp01
Rubyonrails 090715105949-phpapp01
sagaroceanic11
 
Supa fast Ruby + Rails
Supa fast Ruby + Rails
Jean-Baptiste Feldis
 
Ruby On Rails Tutorial
Ruby On Rails Tutorial
sunniboy
 
Introduction to Ruby on Rails
Introduction to Ruby on Rails
Alessandro DS
 
Introduction To Rails
Introduction To Rails
Eric Gruber
 
Rubyonrails 120409061835-phpapp02
Rubyonrails 120409061835-phpapp02
sagaroceanic11
 
Ruby On Rails
Ruby On Rails
iradarji
 
Ruby on Rails
Ruby on Rails
arunv
 
Rubyon Rails
Rubyon Rails
Kevin Gisi
 
Beginners' guide to Ruby on Rails
Beginners' guide to Ruby on Rails
Victor Porof
 
Ruby Rails Web Development
Ruby Rails Web Development
Sonia Simi
 
Ruby On Rails Basics
Ruby On Rails Basics
Amit Solanki
 
A Tour of Ruby On Rails
A Tour of Ruby On Rails
David Keener
 
Ruby On Rails Seminar Basis Softexpo Feb2010
Ruby On Rails Seminar Basis Softexpo Feb2010
arif44
 
Ruby On Rails
Ruby On Rails
anides
 
Introduction to Rails - presented by Arman Ortega
Introduction to Rails - presented by Arman Ortega
arman o
 
Rubyonrails 090715105949-phpapp01
Rubyonrails 090715105949-phpapp01
sagaroceanic11
 
Ruby On Rails Tutorial
Ruby On Rails Tutorial
sunniboy
 
Introduction to Ruby on Rails
Introduction to Ruby on Rails
Alessandro DS
 
Introduction To Rails
Introduction To Rails
Eric Gruber
 
Rubyonrails 120409061835-phpapp02
Rubyonrails 120409061835-phpapp02
sagaroceanic11
 
Ruby On Rails
Ruby On Rails
iradarji
 
Ruby on Rails
Ruby on Rails
arunv
 
Ad

Recently uploaded (20)

ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
 
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
Priyanka Aash
 
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Josef Weingand
 
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
 
OpenPOWER Foundation & Open-Source Core Innovations
OpenPOWER Foundation & Open-Source Core Innovations
IBM
 
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
Connecting Data and Intelligence: The Role of FME in Machine Learning
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
 
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
 
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
 
From Manual to Auto Searching- FME in the Driver's Seat
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
Techniques for Automatic Device Identification and Network Assignment.pdf
Techniques for Automatic Device Identification and Network Assignment.pdf
Priyanka Aash
 
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
janeliewang985
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 
9-1-1 Addressing: End-to-End Automation Using FME
9-1-1 Addressing: End-to-End Automation Using FME
Safe Software
 
"Scaling in space and time with Temporal", Andriy Lupa.pdf
"Scaling in space and time with Temporal", Andriy Lupa.pdf
Fwdays
 
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
 
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
 
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Priyanka Aash
 
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
 
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
Priyanka Aash
 
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Josef Weingand
 
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
 
OpenPOWER Foundation & Open-Source Core Innovations
OpenPOWER Foundation & Open-Source Core Innovations
IBM
 
Lessons Learned from Developing Secure AI Workflows.pdf
Lessons Learned from Developing Secure AI Workflows.pdf
Priyanka Aash
 
Connecting Data and Intelligence: The Role of FME in Machine Learning
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
 
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
 
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
 
From Manual to Auto Searching- FME in the Driver's Seat
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
Techniques for Automatic Device Identification and Network Assignment.pdf
Techniques for Automatic Device Identification and Network Assignment.pdf
Priyanka Aash
 
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
Cluster-Based Multi-Objective Metamorphic Test Case Pair Selection for Deep N...
janeliewang985
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 
9-1-1 Addressing: End-to-End Automation Using FME
9-1-1 Addressing: End-to-End Automation Using FME
Safe Software
 
"Scaling in space and time with Temporal", Andriy Lupa.pdf
"Scaling in space and time with Temporal", Andriy Lupa.pdf
Fwdays
 
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
 
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
 
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Priyanka Aash
 

Server-side Web development via Ruby on Rails

  • 1. Ruby on RailsServer-side web development VladStoianVictor Porof
  • 2. What we’ll talk aboutWhat is Ruby on Rails?A brief historyMVC architecture in a nutshellDistinctive framework featuresWhy Ruby? Why Rails?Demo
  • 3. What is RoR?Open SourceAbstraction providing generic server-side functionalityUsed for web application developmentIt’s a framework for the Ruby language..so don’t confuse it with plain Ruby!
  • 4. A brief historyOriginates in David Heinemeier Hansson’s workFirst released in July 2004Apple ships RoR with Mac OS X Leopard since 2007Major new developments with v2.3 in 2009TemplatesGenerate skeleton applicationsCustom gems and configurationsLatest: v3.0.5, 27 February 2011
  • 5. MVC architectureRoR is based on the Model-View-Controller designIt’s an architectural development patternWidely used in many other frameworks:Oracle Application Framework, Cocoon, JSF (Java)ASP.NET (C#)SproutCore, JavascriptMVC (Javascript)Django, Pylons (Python)CakePHP(PHP)PureMVC (many languages)
  • 7. MVC on RailsModels are Ruby classes, used to store and validate dataHandles migrationsThey talk to databasesMySQLSQLitePostgreSQLNoSQLMongoDBCassandra“Chubby guy in the back room” crunching the numbers
  • 8. Model snippetclass Person < ActiveRecord::Basevalidates_presence_of :namehas_many :wifesendPerson.create(:name => ”Muhammad Ali”).valid? # => truePerson.create(:name => nil).valid? # => false
  • 9. Migration snippetclass AddReceiveNewsletterToUsers < ActiveRecord::Migrationdefself.upchange_table :users do |t|t.boolean :receive_newsletter, :default => false endUser.update_all ["receive_newsletter = ?", true] enddefself.downremove_column :users, :receive_newsletter endend
  • 10. MVC on RailsWhat the user seesHTML, CSS, XML, Javascript (jQuery)JSON, RSS, AtomAutomatically generated “view-puppets”Visual representation of dataDoes not have direct access to the model!It shouldn’t do lots of processing or calculation
  • 11. View snippet <!-- app/views/items/new.rhtml --> <%= form_tag :action => “create” %> Name: <%= text_field“item”, “name”%><br/>Email: <%= text_field“item”, ”email”%><br/> Password: <%= hidden_field “item”, “password”%><br/> <%= submit_tag %> <%= end_form_tag %>
  • 12. MVC on RailsGateway between the model and the viewHandles user requestsDoes parsing and data submissionsTakes care of sessions, cookiesWorks out what data to show and what views to render”The best controller: it gives orders without knowing (or caring) how it gets done”
  • 13. Controller snippetclassItemsController < ApplicationController def edit @item = Item.find(params[:id])ifrequest.post? @item.update_attributes(params[:item])redirect_to :action => 'edit', :id => @item.id end end end
  • 14. MVC on RailsTo summarize:Keep your view code skinnyKeep your controller code skinnyThe fatness is in the model
  • 15. Distinctive framework featuresCode generatorsAwesome built-in functions => rapid developmentTons of “gems” to choose fromCross-platform compatibilityAutomated operation (CRUD)Create, Retrieve, Automate and DeleteSimplified testing (Rake script)
  • 16. Code generator snippet#model generator (general)ruby script/generate model model_name #(in v2.3)rails generate model model_name #(in v3)#model generator (example)rails generate model user name:stringhashed_password:string#controller generator (general)ruby script/generate controller controller_namemethod_name(s) (in v2.3)rails generate controller controller_namemethod_name(s) (in v3)#controller generator (example)rails generate controller store index
  • 18. Famous projects on RailsTwitter (microblogging)Crunchbase (companies database)BaseCamp (project management)Hulu (online tv)Yellowpages.com (phone database)Xing (business network)
  • 19. Why Ruby?Interpreted language => greater flexibilityProvides JIT (just in time compilation)Garbage collectionAble to generate code on the flyCleaner syntax (no more “Verbose verbose is too verbose for verbose”)Many implementations:Jruby, IronRuby, Rubinius(Ruby + C++), MacRuby (ObjC)
  • 20. Why Rails?Based on RubyEasy to implement CGI scriptsRapid web-application developmentDesigned to make programming work easierLess coding, more functionalityThousands of pluginsDon’t reinvent the wheel