SlideShare a Scribd company logo
Ruby on Rails Workshop NYU ITP 2010 Presented by Daniel Tsadok
What is Ruby on Rails?
Why Ruby on Rails? Why not PHP?
Organization
Rails 2 vs. Rails 3
Ruby
Run  irb  in the terminal OR Create a text file (.rb) and run:  ruby filename.rb
puts(“Hello, World!”)
#puts(“Hello, World!”)
s = “Hello, World!” puts(s)
def say_hello(name) puts(“Hello, #{name}!”) end say_hello(“Daniel”)
#look Ma, no parentheses! def say_hello name puts “Hello, #{name}!” end say_hello “Daniel”
Everything is an Object
1 + 1
1.class 1.methods 1.+(1)
class Fixnum alias :+ :plus end one = 1 one.plus(1)
Loop It Up
ar = [1, 2, 3] ar.length for i in ar puts i end
3.times do puts “Hip, Hip, Hooray!” end
ar = [1, 2, 3] ar.length ar.each do |i| puts i end
ar = %w(Red Green Blue) puts ar.inspect ar.each {|w| puts w} puts ar[1]
h = { “ r” => “Red”, “ g” => “Green”, “ b” => “Blue” } h.keys h.each do |k, v| puts “#{k}: #{v}” end
Rails
Rails Principles
Convention Over Configuration
Don’t Repeat Yourself
Model View Controller
rails hello_rails
Controller
script/generate script/generate controller script/generate controller hello
app/controllers/hello_controller.rb def index render :text => “Hello!” end
Routes
config/routes.rb map.connect ‘:controller/:action/:id`
map.connect ‘/hello’, :controller => ‘hello’, :action => ‘index’
map. hello  ‘/hello’, :controller => ‘hello’, :action => ‘index’
script/server http://localhost:3000/hello
map.connect ‘/hello/ :name ’, :controller => ‘hello’, :action => ‘index’
def index render :text => “Hello, #{params[:name]}!” end
script/generate controller guess
map.connect ‘/guess/:name’, :controller => ‘guess’ --------------------------------- def index if params[:name] == “daniel” render :text => “You got it!” else render :text => “Not quite!” end end
map.connect ‘/guess/daniel’, :controller => ‘guess’, :action => ‘right’ map.connect ‘/guess/:name’, :controller => ‘guess’, :action => ‘wrong’
app/controllers/guess_controller.rb def right render :text => “You got it!” end def wrong render :text => “Not quite!” end
Filters
app/controllers/hello_controller.rb before_filter :check_id def index end protected def check_id if params[:id] != “Daniel” redirect_to “http://www.nyu.edu” end end
View
app/views/guess/right.html.erb --- <h1>Right!</h1> app/views/guess/wrong.html.erb --- <h1>It’s not <%= params[:name] %></h1>
Layouts
app/views/layouts/main.html.erb
<html> <head> <title>Title Goes Here</title> </head> <body> <div id=“header”>…</div> <div id=“main”> <%= yield %> </div> <div id=“footer”>…</div> </body> </html>
app/controllers/guess_controller.rb class GuestController < Applica... layout “main” def right end def wrong end end
Model
ORM
mysql> select * from itp_students; +--------+--------+----------------+ | name  | email  | advisor  | +--------+--------+----------------+ | Daniel | dmt321 | Shawn  | | Bob  | brb555 | DanO  | +--------+--------+----------------+
student = ItpStudent.new student.name = “Daniel” student.email = “...” student.advisor = “Shawn” student.save
INSERT INTO itp_students (name, email, advisor) VALUES (‘Daniel’, ‘...’, ‘Shawn’);
student = ItpStudent.find_by_name “Daniel” student.name = “Daniel T” student.save
UPDATE itp_students SET name = ‘Daniel T’ WHERE name = ‘Daniel’;
config/database.yml
script/generate model ItpStudent name:string email:string advisor:string
db/migrate/..._create_itp_students.rb
script/generate migration add_gpa_to_itp_student gpa:integer
rake db:migrate
$ script/console Loading development environment (Rails 2.3.5) >>  ItpStudent => ItpStudent(id: integer, name: string, email: string, advisor: string, created _at: datetime, updated_at: datetime, gpa: integer)
>> student = ItpStudent.new >> student.name = “Daniel” >> student.save!
Validations
class ItpStudent < ActiveRecord::Base validates_presence_of :name end
>> student = ItpStudent.new >> student.valid? => false >> student.save => false >> student.save! ActiveRecord::RecordInvalid: Validation failed: Name can't be blank
Scopes
class ItpStudent < ActiveRecord::Base named_scope :passing => { :conditions => “gpa > 2” } named_scope :advised_by => {|x| :conditions => {:advisor => x} } end
>> ItpStudent.passing >> ItpStudent.advised_by ‘Shawn’ >> ItpStudent.advised_by(‘Shawn’).passing
Relations (has_many, belongs_to)
class ItpStudent < ActiveRecord::Base has_many :classes belongs_to :itp_class end
>> student = ItpStudent.first >> student.classes.first
MOAR !!!
If you got this far… Partials Helpers (built-in, user-defined) Testing External libraries (plugins, gems)
Further Reading ruby-doc.org www.rubyonrails.org guides.rubyonrails.org api.rubyonrails.org planetrubyonrails.com railscasts.com peepcode.com
Thanks!

More Related Content

What's hot (20)

PDF
YAPC::Asia 2010 Twitter解析サービス
Yusuke Wada
 
PPTX
Webrtc mojo
bpmedley
 
KEY
(Ab)Using the MetaCPAN API for Fun and Profit
Olaf Alders
 
PPT
Building an e:commerce site with PHP
webhostingguy
 
KEY
Keeping it small: Getting to know the Slim micro framework
Jeremy Kendall
 
PDF
PerlDancer for Perlers (FOSDEM 2011)
xSawyer
 
PDF
Extracting ruby gem
Yura Tolstik
 
PDF
Blog Hacks 2011
Yusuke Wada
 
PPT
Programming For Designers V3
sqoo
 
KEY
Mojo as a_client
Marcus Ramberg
 
PDF
Path::Tiny
waniji
 
PDF
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
Puppet
 
PDF
RESTful web services
Tudor Constantin
 
PDF
Clean Code Tips (Day 1 )
Ahmed Abd El Ftah
 
ODP
Dancer's Ecosystem
Alexis Sukrieh
 
PDF
My First Ruby
Murray Steele
 
PDF
Perl web frameworks
diego_k
 
PDF
Inside Bokete: Web Application with Mojolicious and others
Yusuke Wada
 
ODP
An introduction to Rex - FLOSS UK DevOps York 2015
Andy Beverley
 
PDF
Learning Perl 6
brian d foy
 
YAPC::Asia 2010 Twitter解析サービス
Yusuke Wada
 
Webrtc mojo
bpmedley
 
(Ab)Using the MetaCPAN API for Fun and Profit
Olaf Alders
 
Building an e:commerce site with PHP
webhostingguy
 
Keeping it small: Getting to know the Slim micro framework
Jeremy Kendall
 
PerlDancer for Perlers (FOSDEM 2011)
xSawyer
 
Extracting ruby gem
Yura Tolstik
 
Blog Hacks 2011
Yusuke Wada
 
Programming For Designers V3
sqoo
 
Mojo as a_client
Marcus Ramberg
 
Path::Tiny
waniji
 
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
Puppet
 
RESTful web services
Tudor Constantin
 
Clean Code Tips (Day 1 )
Ahmed Abd El Ftah
 
Dancer's Ecosystem
Alexis Sukrieh
 
My First Ruby
Murray Steele
 
Perl web frameworks
diego_k
 
Inside Bokete: Web Application with Mojolicious and others
Yusuke Wada
 
An introduction to Rex - FLOSS UK DevOps York 2015
Andy Beverley
 
Learning Perl 6
brian d foy
 

Viewers also liked (19)

PPS
Abcdef
Nannou Nanny
 
PDF
La musica
Juan Manco
 
PDF
Making a Light Reflector ~ Teacher Guide, Organic Gardening
School Vegetable Gardening - Victory Gardens
 
PPTX
4 ltr powerpoint2010_ch20_pr1a_michaelagaffney_2
Michaela Gaffney
 
PDF
Breast cancer awareness
Deepak Singh
 
PPT
香港六合彩
yyou
 
PPTX
Futbol es mi pasion
Julian Ochoa Barco
 
PPTX
^^ Tipos de energía^^
Locoman145
 
PDF
Portfolio1
guest5e87f9
 
PPT
Caso PTI n-plate. Dr García Erce
José Antonio García Erce
 
ODP
MAPA CONCEPTUAL II GUERRA MUNDIAL
luchoportuano25
 
PDF
Chapter 3
Robioul Hasan
 
PPT
Breast Cancer Awareness Month - ROJoson's Lecture - 16oct22
Reynaldo Joson
 
PDF
Chapter 14
Robioul Hasan
 
PPTX
How to Do Physical Examination of the Breasts
Reynaldo Joson
 
PPTX
Capitulo 23 Casos de Embarques
profrcconcepcion
 
PPTX
Capitulo 22 Casos de Radiacion
profrcconcepcion
 
PPTX
Capitulo 21 Casos Descompuestos
profrcconcepcion
 
PPT
Capitulo I Los Principios y Practicas del Embalsamamiento
profrcconcepcion
 
Abcdef
Nannou Nanny
 
La musica
Juan Manco
 
Making a Light Reflector ~ Teacher Guide, Organic Gardening
School Vegetable Gardening - Victory Gardens
 
4 ltr powerpoint2010_ch20_pr1a_michaelagaffney_2
Michaela Gaffney
 
Breast cancer awareness
Deepak Singh
 
香港六合彩
yyou
 
Futbol es mi pasion
Julian Ochoa Barco
 
^^ Tipos de energía^^
Locoman145
 
Portfolio1
guest5e87f9
 
Caso PTI n-plate. Dr García Erce
José Antonio García Erce
 
MAPA CONCEPTUAL II GUERRA MUNDIAL
luchoportuano25
 
Chapter 3
Robioul Hasan
 
Breast Cancer Awareness Month - ROJoson's Lecture - 16oct22
Reynaldo Joson
 
Chapter 14
Robioul Hasan
 
How to Do Physical Examination of the Breasts
Reynaldo Joson
 
Capitulo 23 Casos de Embarques
profrcconcepcion
 
Capitulo 22 Casos de Radiacion
profrcconcepcion
 
Capitulo 21 Casos Descompuestos
profrcconcepcion
 
Capitulo I Los Principios y Practicas del Embalsamamiento
profrcconcepcion
 
Ad

Similar to Rails 2010 Workshop (20)

KEY
Desarrollando aplicaciones web en minutos
Edgar Suarez
 
PDF
Rails workshop for Java people (September 2015)
Andre Foeken
 
PDF
Ruby on Rails - Introduction
Vagmi Mudumbai
 
PDF
Story for a Ruby on Rails Single Engineer
TylerJohnson988371
 
PDF
Ruby on Rails
bryanbibat
 
PDF
td_mxc_rubyrails_shin
tutorialsruby
 
PDF
td_mxc_rubyrails_shin
tutorialsruby
 
PPT
Ruby On Rails Tutorial
sunniboy
 
PPT
An introduction-to-ruby-on-rails
vinicorp
 
PPT
An Introduction to Ruby on Rails 20100506
Vu Hung Nguyen
 
PDF
Testing Merb
Yehuda Katz
 
KEY
Rails by example
Angelo van der Sijpt
 
PDF
Introduction to Rails - presented by Arman Ortega
arman o
 
KEY
Refactor like a boss
gsterndale
 
PDF
Ruby on Rails 中級者を目指して - 大場寧子
Yasuko Ohba
 
PDF
Ruby on Rails Presentation
Michael MacDonald
 
ODP
A Toda Maquina Con Ruby on Rails
Rafael García
 
PDF
Ruby on Rails 2.1 What's New
Libin Pan
 
PDF
Rails 2.3 and Rack - NHRuby Feb 2009
bturnbull
 
PDF
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009
Yasuko Ohba
 
Desarrollando aplicaciones web en minutos
Edgar Suarez
 
Rails workshop for Java people (September 2015)
Andre Foeken
 
Ruby on Rails - Introduction
Vagmi Mudumbai
 
Story for a Ruby on Rails Single Engineer
TylerJohnson988371
 
Ruby on Rails
bryanbibat
 
td_mxc_rubyrails_shin
tutorialsruby
 
td_mxc_rubyrails_shin
tutorialsruby
 
Ruby On Rails Tutorial
sunniboy
 
An introduction-to-ruby-on-rails
vinicorp
 
An Introduction to Ruby on Rails 20100506
Vu Hung Nguyen
 
Testing Merb
Yehuda Katz
 
Rails by example
Angelo van der Sijpt
 
Introduction to Rails - presented by Arman Ortega
arman o
 
Refactor like a boss
gsterndale
 
Ruby on Rails 中級者を目指して - 大場寧子
Yasuko Ohba
 
Ruby on Rails Presentation
Michael MacDonald
 
A Toda Maquina Con Ruby on Rails
Rafael García
 
Ruby on Rails 2.1 What's New
Libin Pan
 
Rails 2.3 and Rack - NHRuby Feb 2009
bturnbull
 
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009
Yasuko Ohba
 
Ad

Recently uploaded (20)

PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 

Rails 2010 Workshop

Editor's Notes

  • #3: Ruby on Rails is a web development framework that makes building complex web applications much easier. Ruby is the language in which Rails is built.
  • #4: http://itp.nyu.edu/~dmt321/bad-php.txt http://itp.nyu.edu/~dmt321/better-php.txt
  • #6: Rails 3 is on the verge of being released – it’s already out in beta. Some of the syntax, especially in routing, will be changed in Rails 3. But the fundamental concepts are the same.
  • #10: Comments
  • #26: table names, primary key, location of files
  • #27: EXAMPLES
  • #36: You can created Named Routes as well – this creates the hello_url and hello_path helpers.
  • #38: Adding parameter :name
  • #41: More sane way to do it  Also notice that :action =&gt; “index” is optional
  • #47: Convention over configuration – Rails knows where to look for views.
  • #49: Convention over configuration – Rails knows where to look for layouts.
  • #51: Removed render :text code
  • #53: ORM is Object-Relational Mapping. It converts a row in a database table to an object.
  • #58: This is a lie. In fact Rails would not build a query like this.
  • #59: There are three different environments (more are possible). We will work primarily with the “development” environment.
  • #64: Notice the fields that were not in the migration file id - more convention over configuration
  • #71: Chained scopes
  • #73: Convention over configuration – looks for itp_student.advisor_id and classes.itp_student_id