SlideShare a Scribd company logo
Ruby On Rails



     A brief tutorial

    Avik Sengupta




   © 2005 Avik Sengupta. All Rights Reserved.   1
Agenda

Introduce Rails via these slides
Show me the code!
  Code up a Rails application from scratch

(This tutorial assumes a very limited knowledge of
  Ruby ... did you attend Premshree or Yogi's talks?)




                  © 2005 Avik Sengupta. All Rights Reserved.            2
Rails

     “Rails is a full-stack, open-source web
   framework in Ruby for writing real-world
applications with joy and less code than most
     frameworks spend doing XML sit-ups”
         Rails Creator - David H. Hansson




                  © 2005 Avik Sengupta. All Rights Reserved.           3
What is Rails

Full Stack
  Model (Object Relation Mapping) – Active Record
  View – Action View +ERb
  Controller – Action Controller
  Mail integration – ActionMailer
  Web Services – Action Web services
..therefore, all layers work seamlessly (DRY)




                 © 2005 Avik Sengupta. All Rights Reserved.                   4
The Rails request cycle




© 2005 Avik Sengupta. All Rights Reserved.                  5
Active Record

Automated mappings :

Given this table..
      CREATE TABLE entries (
         id int(11) NOT NULL auto_increment,
         name varchar(255),
         comments varchar(255),
         PRIMARY KEY (id)
      );




                     © 2005 Avik Sengupta. All Rights Reserved.                   6
Active Record
You can do
     class Entry < ActiveRecord::Base
       # nothing here!
     end

     entry = Entry.new
     entry.name = "John"
     entry.comments = "What a great Web site!"
     entry.save

     entry = Entry.find(1)
     puts entry.name # output: "John"


                   © 2005 Avik Sengupta. All Rights Reserved.                   7
Active Record

  Associations only need to be declared
class Firm < ActiveRecord::Base
   has_many :clients
   has_one :account
   belongs_to :conglomerate
end

firm.clients.each do |client| {...}
firm.has_clients?




                  © 2005 Avik Sengupta. All Rights Reserved.                   8
Action Controller

Action Controller
  Handles the entire request cycle
  Actions grouped into Controller
  Each action is method in the controller class
  Instance variables are passed to the view

class GuestbookController <
  ActionController::Base
  def index
    @entries = Entries.find_all
  end
end
                    © 2005 Avik Sengupta. All Rights Reserved.                       9
Views

Templates in Embedded Ruby (like JSP or ASP)
Expression language is Pure Ruby
Helper classes provide common functionality for
strings, dates, forms etc.
<html>
  <body>
    <h1>Cookbook</h1>
    <% for e in @entries %>
    <p><%= e.name %>: <%= e.description %></p>
    <% end %>
  </body>
</html>

                © 2005 Avik Sengupta. All Rights Reserved.           10
Action Mailer

Integrate e-mails from Rails applications
# send email with attachment
def report_notification(recipient)
  recipients recipient.email_address_with_name
  subject "Your Report"
  from "owner@app.com"

  attachment :content_type => "image/gif", :body =>
  File.read("logo.gif")

  attachment "image/gif" do |a|
    a.body = generate_chart()
  end
end

                  © 2005 Avik Sengupta. All Rights Reserved.                   11
Action Web Services

Server side WS and XML-RPC protocols
Export API's as Web Services




              © 2005 Avik Sengupta. All Rights Reserved.                         12
Demo
     Build a web based cookbook, live, from scratch.

  For reference, some of the steps we will go through are
illustrated in the following slides. However, for the tutorial,
          we will write the code directly ourselves!




                       © 2005 Avik Sengupta. All Rights Reserved.          13
Downloads and Installation
Install Ruby
   On Windows you can use the One-Click installer. For other
   platforms, use your platform packages
Install RubyGems (a ruby package management
system)
   Download from http://rubyforge.org/projects/rubygems/
   Unpack the downloaded archive and in that directory run the
   command:
   ruby install.rb
Install Rails
   From the command line execute: From the command line
   execute:
   gem install rails

                      © 2005 Avik Sengupta. All Rights Reserved.        14
First Steps

Generate Application Structure
$ rails cookbook
Create Database
Generate Models and Controllers
Use scaffold to create basic app




                © 2005 Avik Sengupta. All Rights Reserved.                 15
More code...

Flesh out the application
  Create Views
     Use partials and helpers
     Use layouts
  Implement Validations
  Model complex relationships




                     © 2005 Avik Sengupta. All Rights Reserved.                  16
Advanced Stuff

Callbacks
Transactions
Caching
Rails makes AJAX easy
  Go to Vamsee Kankala's tutorial
Rails makes testing easy
  Again, go to Vamsee's tutorial




                  © 2005 Avik Sengupta. All Rights Reserved.                    17
Questions?




Curiosity killed the cat... or did it?




       © 2005 Avik Sengupta. All Rights Reserved.                18
Credits

This presentation inspired by
  Rolling with Rails (OnLamp) by Curt Hibbs
     http://www.onlamp.com/pub/a/onlamp/2005/01/20/rails.html
  Presentation at Chicago ACM by Ryan Platte and John
  W. Long
     http://www.ruby-doc.org/docs/Get to the Point Development with Ru




                       © 2005 Avik Sengupta. All Rights Reserved.             19
More Info

Main Ruby Site
  http://www.ruby-lang.org
One Click Ruby Installer for Windows
  http://rubyinstaller.rubyforge rubyforge.org
Main Rails Site
  http://www.rubyonrails.org
This presentation
  http://www.sengupta.net/talks/




                   © 2005 Avik Sengupta. All Rights Reserved.               20

More Related Content

PPTX
Ruby on rails for beginers
PDF
OSOM - Ruby on Rails
ZIP
Rails 3 (beta) Roundup
PPT
Rubyonrails 090715105949-phpapp01
PPT
Ruby On Rails
PPT
Jasig Rubyon Rails
PPT
Introduction to Ruby on Rails
PPTX
Ruby on Rails All Hands Meeting
Ruby on rails for beginers
OSOM - Ruby on Rails
Rails 3 (beta) Roundup
Rubyonrails 090715105949-phpapp01
Ruby On Rails
Jasig Rubyon Rails
Introduction to Ruby on Rails
Ruby on Rails All Hands Meeting

What's hot (20)

PDF
JCR In Action (ApacheCon US 2009)
PPTX
Java Web services
PDF
Security Goodness with Ruby on Rails
PPTX
Melbourne User Group OAK and MongoDB
PDF
Padrino - the Godfather of Sinatra
PPTX
Scaling with swagger
PDF
Ror Seminar With agilebd.org on 23 Jan09
PPT
Content Storage With Apache Jackrabbit
PPT
Ruby On Rails
PDF
Alfresco Content Modelling and Policy Behaviours
 
PPT
Apache Velocity
PPT
Web development basics (Part-7)
PPTX
Intro to Rails and MVC
PPTX
Apache Cayenne: a Java ORM Alternative
PDF
Introduction to JavaScript
PPTX
Content Modeling Behavior
ODP
Ruby On Rails - Rochester K Linux User Group
PDF
S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010
ODP
ORM, JPA, & Hibernate Overview
PDF
Rails - getting started
JCR In Action (ApacheCon US 2009)
Java Web services
Security Goodness with Ruby on Rails
Melbourne User Group OAK and MongoDB
Padrino - the Godfather of Sinatra
Scaling with swagger
Ror Seminar With agilebd.org on 23 Jan09
Content Storage With Apache Jackrabbit
Ruby On Rails
Alfresco Content Modelling and Policy Behaviours
 
Apache Velocity
Web development basics (Part-7)
Intro to Rails and MVC
Apache Cayenne: a Java ORM Alternative
Introduction to JavaScript
Content Modeling Behavior
Ruby On Rails - Rochester K Linux User Group
S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010
ORM, JPA, & Hibernate Overview
Rails - getting started
Ad

Similar to Avik_RailsTutorial (20)

PDF
Node.js Workshop
PDF
Web sphere administration
PDF
Serverless Java - Challenges and Triumphs
PPTX
COP_RoR_QuArrk_Session_Oct_2022.pptx
KEY
Ruby On Rails
PDF
Is Enterprise Java Still Relevant (JavaOne 2015 session)
PDF
From Java to Ruby...and Back
PDF
Wicket Presentation @ AlphaCSP Java Web Frameworks Playoff 2008
PPT
Viridians on Rails
PDF
&lt;img src="../i/r_14.png" />
PDF
Build Comet applications using Scala, Lift, and &lt;b>jQuery&lt;/b>
PPTX
AEM and Sling
PPTX
AEM and Sling
PDF
Serverless Java Challenges & Triumphs
PPT
Flex360 Milan 2008 - Flex & Webservices
PPTX
The future of ASP.NET / CodeCamp/Iasi 25 Oct 2014
PDF
Guides To Analyzing WebKit Performance
PDF
Practical WebAssembly with Apex, wasmRS, and nanobus
PPTX
Web Apps atop a Content Repository
PDF
Java EE 7 et ensuite pourquoi pas JavaScript sur le serveur!
Node.js Workshop
Web sphere administration
Serverless Java - Challenges and Triumphs
COP_RoR_QuArrk_Session_Oct_2022.pptx
Ruby On Rails
Is Enterprise Java Still Relevant (JavaOne 2015 session)
From Java to Ruby...and Back
Wicket Presentation @ AlphaCSP Java Web Frameworks Playoff 2008
Viridians on Rails
&lt;img src="../i/r_14.png" />
Build Comet applications using Scala, Lift, and &lt;b>jQuery&lt;/b>
AEM and Sling
AEM and Sling
Serverless Java Challenges & Triumphs
Flex360 Milan 2008 - Flex & Webservices
The future of ASP.NET / CodeCamp/Iasi 25 Oct 2014
Guides To Analyzing WebKit Performance
Practical WebAssembly with Apex, wasmRS, and nanobus
Web Apps atop a Content Repository
Java EE 7 et ensuite pourquoi pas JavaScript sur le serveur!
Ad

More from tutorialsruby (20)

PDF
&lt;img src="../i/r_14.png" />
PDF
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
PDF
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
PDF
&lt;img src="../i/r_14.png" />
PDF
&lt;img src="../i/r_14.png" />
PDF
Standardization and Knowledge Transfer – INS0
PDF
xhtml_basics
PDF
xhtml_basics
PDF
xhtml-documentation
PDF
xhtml-documentation
PDF
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
PDF
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
PDF
HowTo_CSS
PDF
HowTo_CSS
PDF
BloggingWithStyle_2008
PDF
BloggingWithStyle_2008
PDF
cascadingstylesheets
PDF
cascadingstylesheets
&lt;img src="../i/r_14.png" />
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
Standardization and Knowledge Transfer – INS0
xhtml_basics
xhtml_basics
xhtml-documentation
xhtml-documentation
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
HowTo_CSS
HowTo_CSS
BloggingWithStyle_2008
BloggingWithStyle_2008
cascadingstylesheets
cascadingstylesheets

Recently uploaded (20)

PDF
Machine learning based COVID-19 study performance prediction
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
MYSQL Presentation for SQL database connectivity
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
A Presentation on Artificial Intelligence
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Modernizing your data center with Dell and AMD
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Machine learning based COVID-19 study performance prediction
NewMind AI Weekly Chronicles - August'25 Week I
MYSQL Presentation for SQL database connectivity
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Chapter 3 Spatial Domain Image Processing.pdf
Network Security Unit 5.pdf for BCA BBA.
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
A Presentation on Artificial Intelligence
Building Integrated photovoltaic BIPV_UPV.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Approach and Philosophy of On baking technology
Modernizing your data center with Dell and AMD
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
The Rise and Fall of 3GPP – Time for a Sabbatical?
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Understanding_Digital_Forensics_Presentation.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
“AI and Expert System Decision Support & Business Intelligence Systems”
CIFDAQ's Market Insight: SEC Turns Pro Crypto

Avik_RailsTutorial

  • 1. Ruby On Rails A brief tutorial Avik Sengupta © 2005 Avik Sengupta. All Rights Reserved. 1
  • 2. Agenda Introduce Rails via these slides Show me the code! Code up a Rails application from scratch (This tutorial assumes a very limited knowledge of Ruby ... did you attend Premshree or Yogi's talks?) © 2005 Avik Sengupta. All Rights Reserved. 2
  • 3. Rails “Rails is a full-stack, open-source web framework in Ruby for writing real-world applications with joy and less code than most frameworks spend doing XML sit-ups” Rails Creator - David H. Hansson © 2005 Avik Sengupta. All Rights Reserved. 3
  • 4. What is Rails Full Stack Model (Object Relation Mapping) – Active Record View – Action View +ERb Controller – Action Controller Mail integration – ActionMailer Web Services – Action Web services ..therefore, all layers work seamlessly (DRY) © 2005 Avik Sengupta. All Rights Reserved. 4
  • 5. The Rails request cycle © 2005 Avik Sengupta. All Rights Reserved. 5
  • 6. Active Record Automated mappings : Given this table.. CREATE TABLE entries ( id int(11) NOT NULL auto_increment, name varchar(255), comments varchar(255), PRIMARY KEY (id) ); © 2005 Avik Sengupta. All Rights Reserved. 6
  • 7. Active Record You can do class Entry < ActiveRecord::Base # nothing here! end entry = Entry.new entry.name = "John" entry.comments = "What a great Web site!" entry.save entry = Entry.find(1) puts entry.name # output: "John" © 2005 Avik Sengupta. All Rights Reserved. 7
  • 8. Active Record Associations only need to be declared class Firm < ActiveRecord::Base has_many :clients has_one :account belongs_to :conglomerate end firm.clients.each do |client| {...} firm.has_clients? © 2005 Avik Sengupta. All Rights Reserved. 8
  • 9. Action Controller Action Controller Handles the entire request cycle Actions grouped into Controller Each action is method in the controller class Instance variables are passed to the view class GuestbookController < ActionController::Base def index @entries = Entries.find_all end end © 2005 Avik Sengupta. All Rights Reserved. 9
  • 10. Views Templates in Embedded Ruby (like JSP or ASP) Expression language is Pure Ruby Helper classes provide common functionality for strings, dates, forms etc. <html> <body> <h1>Cookbook</h1> <% for e in @entries %> <p><%= e.name %>: <%= e.description %></p> <% end %> </body> </html> © 2005 Avik Sengupta. All Rights Reserved. 10
  • 11. Action Mailer Integrate e-mails from Rails applications # send email with attachment def report_notification(recipient) recipients recipient.email_address_with_name subject "Your Report" from "owner@app.com" attachment :content_type => "image/gif", :body => File.read("logo.gif") attachment "image/gif" do |a| a.body = generate_chart() end end © 2005 Avik Sengupta. All Rights Reserved. 11
  • 12. Action Web Services Server side WS and XML-RPC protocols Export API's as Web Services © 2005 Avik Sengupta. All Rights Reserved. 12
  • 13. Demo Build a web based cookbook, live, from scratch. For reference, some of the steps we will go through are illustrated in the following slides. However, for the tutorial, we will write the code directly ourselves! © 2005 Avik Sengupta. All Rights Reserved. 13
  • 14. Downloads and Installation Install Ruby On Windows you can use the One-Click installer. For other platforms, use your platform packages Install RubyGems (a ruby package management system) Download from http://rubyforge.org/projects/rubygems/ Unpack the downloaded archive and in that directory run the command: ruby install.rb Install Rails From the command line execute: From the command line execute: gem install rails © 2005 Avik Sengupta. All Rights Reserved. 14
  • 15. First Steps Generate Application Structure $ rails cookbook Create Database Generate Models and Controllers Use scaffold to create basic app © 2005 Avik Sengupta. All Rights Reserved. 15
  • 16. More code... Flesh out the application Create Views Use partials and helpers Use layouts Implement Validations Model complex relationships © 2005 Avik Sengupta. All Rights Reserved. 16
  • 17. Advanced Stuff Callbacks Transactions Caching Rails makes AJAX easy Go to Vamsee Kankala's tutorial Rails makes testing easy Again, go to Vamsee's tutorial © 2005 Avik Sengupta. All Rights Reserved. 17
  • 18. Questions? Curiosity killed the cat... or did it? © 2005 Avik Sengupta. All Rights Reserved. 18
  • 19. Credits This presentation inspired by Rolling with Rails (OnLamp) by Curt Hibbs http://www.onlamp.com/pub/a/onlamp/2005/01/20/rails.html Presentation at Chicago ACM by Ryan Platte and John W. Long http://www.ruby-doc.org/docs/Get to the Point Development with Ru © 2005 Avik Sengupta. All Rights Reserved. 19
  • 20. More Info Main Ruby Site http://www.ruby-lang.org One Click Ruby Installer for Windows http://rubyinstaller.rubyforge rubyforge.org Main Rails Site http://www.rubyonrails.org This presentation http://www.sengupta.net/talks/ © 2005 Avik Sengupta. All Rights Reserved. 20