6. “Learn at least one new [programming] language
every year. Different languages solve the same
problems in different ways. By learning several
different approaches, you can help broaden your
thinking and avoid getting stuck in a rut.”
- David Thomas and Andy Hunt
26. Ruby on Rails
• David Heinemeier Hansson (DHH)
• Began via Basecamp in mid 2003
• Released July 2004
• Full Stack MVC Web Framework
• Easy database-based web apps
27. Accolades
• 2006 Jolt award - Web Dev Tool
• Featured in BusinessWeek, Wired
• DHH “Best Hacker” award from Google
28. Converts
• Dave Thomas
• Bruce Tate
• Stuart Halloway
• Justin Gehtland
• David Geary
• James Duncan Davidson
29. “Rails is the most well thought-out
web development framework I’ve ever
used. And that’s in a decade of doing
web applications for a living. I’ve built
my own frameworks, helped develop
the Servlet API, and have created more
than a few web servers from scratch.
Nobody has done it like this before.”
-James Duncan Davidson, Creator of
Tomcat and Ant
30. Platform
• MySQL, PostgreSQL, SQLite, Oracle,
SQL Server, DB2, or Firebird
• develop anywhere
• Apache or LightTPD + FastCGI for
production
31. * Done via intelligent
reflection and
metaprogramming
* Emphasis on writing code
to get stuff done - avoid
boilerplate
* Scaffolding handles left
over boilerplate
DRY - Don’t
Repeat Yourself
37. create table orders (
id int not null auto_increment,
name varchar(100) not null,
email varchar(255) not null,
address text not null,
pay_type char(10) not null,
shipped_at
datetime null,
primary key (id)
);
41. create table order_lines (
id int not null auto_increment,
description varchar(100) not null,
order_id
int
not null,
primary key (id),
constraint fk_order foreign key (order_id)
references orders(id)
);
42. class Order < ActiveRecord::Base
has_many :order_lines
end
class OrderLine < ActiveRecord::Base
belongs_to :order
end
one to many bet ween
orders and order lines
“has_many” is actually a
class level method call
that generates instance
methods
45. quick summary
Gross Income $ 0 Total Tax $ 0
Adjusted Gross Income $ 0 Total Payments $ 0
Total Deductions $ 16,400 Refund Amount $ * confirmation checks t wo
0
Total Taxable Income $ 0 Amount You Owe $ password0fields against each
to file your 2005 federal extension, simply follow these instructions
other
STEP A - Once your e-filed extension has been accepted, you will acceptance is pattern of
*
receive an email with a confirmation number. Enter the confirmation
number on your printed copy of Form 4868 and keep for your records. of ser vice/agreement
terms
checkbox
STEP B - Since you indicated that you are not paying an amount with
Form 4868, there is nothing to mail.
For more information about tax, mortgage and financial services call 1-800-HRBLOCK or visit hrblock.com
46. quick summary
Gross Income $ 0 Total Tax $ 0
Adjusted Gross Income $ 0 Total Payments $ 0
Total Deductions $ 16,400 Refund Amount $ 0
Total Taxable Income $ 0 Amount You Owe $ 0
to file your 2005 federal extension, simply follow these instructions
STEP A - Once your e-filed extension has been accepted, you will
receive an email with a confirmation number. Enter the confirmation
number on your printed copy of Form 4868 and keep for your records.
STEP B - Since you indicated that you are not paying an amount with
Form 4868, there is nothing to mail.
For more information about tax, mortgage and financial services call 1-800-HRBLOCK or visit hrblock.com
47. Much More...
• many to many via has_many :through
• eager loading
• acts_as_list, acts_as_tree
• single table inheritance
• callbacks and observers
50. /app/controllers/weblog_controller.rb:
class WeblogController < ActionController::Base
layout "weblog/layout"
def index
@posts = Post.find_all
end
def display
@post = Post.find(:params[:id])
||= conditional assignment
end operator
def new cart is a non persistent model
@post = Post.new object used for storing/calculating
products
end
“the flash” = place to throw stuff
def create like response messages, error
@post = Post.create(params[:post]) reports that accumulate as a
request is processed
redirect_to :action => "display", :id => @post.id
end
end
51. /app/views/weblog/layout.rhtml:
<html><body>
<%= @content_for_layout %>
</body></html>
/app/views/weblog/index.rhtml:
<% for post in @posts %>
<p><%= link_to(post.title, :action => "display", :id => post.id %></p>
<% end %>
/app/views/weblog/display.rhtml:
<p>
<b><%= post.title %></b><br/>
<b><%= post.content %></b>
</p>
/app/views/weblog/new.rhtml:
<%= form "post" %>
53. ActionPack features
• rxml - XML Builders
• rhtml - HTML templates
• helpers - module to assist the view
• form and field helpers
• layouts and partials - similiar to tiles
• page caching and fragment caching
54. ! &'())*+,%-.,//".0.1
!"#'4,+:
''!3&4$'('J&4$7!5,K"#$#%&B*+,CL
"%!
" "!$-0.2-&/
>D('?9$%E:#F'*#8:+95'(-'G&#A4G2'*+,'(-'!3&4$'D-
>D(':4H:E!4I,'''''''''''G3&4$G2'G5#%4G''D->@"-
>D(':4H:E!4I,'''''''''''G3&4$G2'G8935:$;G''D->@"-
>D('"#&&<9$,E!4I,'G3&4$G2'G"#&&<9$,G''D->@"-
7'7'7
! NO4'#""I+8#:+95'$484+A4&'#'$4P34&:'
>D('45,E?9$%E:#F'D-
:9'4,+:'#'3&4$7'Q:'$4#,&':O4',#:#'+5:9'
#'54<'J&4$'%9,4I'9MR48:7 hash created with user
attributes for easy
" NO4'4,+:7$O:%I':4%"I#:4'+&'8#II4,7'Q:' update/save
3&4&':O4'+5?9$%#:+95'+5':O4'3&4$'
9MR48:':9'F454$#:4777
# >?9$%'#8:+95(6@%;#""@&#A4@./016-
''''>+5"3:'5#%4(63&4$B5#%4C6'777'- field helpers make input
# :O4'SNTU'+&'&45:':9':O4'M$9<&4$7'
''''>+5"3:'5#%4(63&4$B8935:$;C6'777'-
(s) easy
''''>+5"3:'5#%4(63&4$B"#&&<9$,C6'777'-
VO45':O4'$4&"95&4'+&'$484+A4,777
''''7'7'7
>@?9$%-
$ :O4'"#$#%4:4$&'#$4'4H:$#8:4,'+5:9'#'
54&:4,'O#&O7'
% NO4'&#A4'#8:+95'3&4&':O4'
"#$#%4:4$&':9'!5,':O4'3&4$'$489$,'
#5,'3",#:4'+:7 $ !"#$#%&'(')
''''*+,'(-'./012
''''*3&4$'(-')'
''''''''*5#%4'(-'6'777'62'
% !"#'&#A4
''''''''*8935:$;'(-'6'777'62
''''''''*"#&&<9$,'(-'6'777'6''=
''3&4$'('J&4$7!5,K"#$#%&B*+,CL
=
''$#'3&4$73",#:4E#::$+M3:4&K"#$#%&B*3&4$CL
'''''777
''"%!
"%!
Figure 17.2: Models, Controllers, and Views Work Together
55. Ajax Support
• Ajax support built in since March ’05
• Built on Prototype and Scriptaculous
• Updating forms and tables via Ajax is trivial
• Best Ajax support of any web framework
56. Other Stuff
• Awesome Testing support built in
• Generators/scaffolding
• Migrations - refactor your database
• Capistrano - automate deployment
• Huge, helpful community
62. • Legacy databases
• Tool support
• Deployment is hard
• Internationalization
• Its different
• Its advanced
63. The Future
• Rails growth will continue
• Its influence is already felt everywhere
• JRuby could be huge
• Its biggest impact may be felt in future
frameworks