Ruby On Rails
Ruby On Rails
or,
why are you wasting your…
What is Ruby?
What is Rails?
Live Demonstration
Development Metrics for Real Rails
Applications
Rails Features
Resources for more information
What is Ruby?
Short Answer:
Ruby is the successful combination
SmallTalk's conceptual elegance, Python's
ease of use and learning, and Perl's
pragmatism.
Long Answer:
Well… see the following slides.
What is Ruby?
Performance
although it rivals Perl and Python
Threading model
Does not use native threads
Who Uses Ruby?
Well Known Developer’s Using Ruby
Evangelists
• Dave Thomas & Andrew Hunt
– Authors of “The Pragmatic Programmer”
Enthusiasts
• Ron Jefferies *
• Martin Fowler *
• Jack Herrington
Positive Mentions
• Alistair Cockburn *
• Kent Beck *
• Ward Cunningham *
• Bret Pettichord *
• Brian Marick *
• Paul Graham * Notice the heavy
• Doug Lea representation from
• Bjarne Stroustrup Agile Software
• Brad Cox Development
• Bruce Perens community.
• Howard Lewis Ship
What is Rails?
Short Answer:
An extremely productive web-application
framework that is written in Ruby by
David Heinemeier Hansson.
Long Answer:
Well… see the following slides.
What is Rails?
Less Code
Requires fewer total lines of code than
other frameworks spend setting up their
XML configuration files.
Full Stack
Being a full-stack framework means that all
layers are built to work seamlessly
together. That way you Don’t Repeat
Yourself (DRY).
What is Rails?
Convention over Configuration
Rails shuns configuration files in favor of
conventions, reflection and dynamic run-
time extensions.
Configure your application by making it
Your code is the configuration!
This means the end of XML files telling a
story that has already been told in your
code.
It means no compilation phase: Make a
change, see it work.
Meta-data is an implementation detail left
for the framework to handle.
Rails Demonstration
The Finished Forum Example
RubyBB
by Russ Smith
http://rubybb.readbim.com/
Launched after
4,000 Lines of Code.
2 man-months of
programming by a
single developer
(the Rails author).
Rails Testimonials
“I'm absolutely floored by how fast I'm developing with
Rails. Stuff that would have taken me over a week in
Java + Web Work2 + Velocity + Hibernate has taken me
a little over a day with Rails. I'm not even going to try to
compare it to my current client's project which requires
Struts.”
- Anoop Ranganath
firm = Firm.find(id);
firm.clients.each do |client|
...some-interesting-processing...
end
Active Record
Validation rules can differ for new or existing
objects.
def validate_on_update
errors.add_on_empty "password"
end
end
Active Record
Callbacks as methods or queues on the entire
lifecycle (instantiation, saving, destroying,
validating, etc).
# Object transaction
Account.transaction(david, mary) do
david.withdrawal(100)
mary.deposit(100)
end
Active Record
Reflections on columns, associations, and
aggregations
reflection = Firm.reflect_on_association(:clients)
ActiveRecord::Base.establish_connection(
:adapter => "sqlite",
:dbfile => "dbfile“
)
ActiveRecord::Base.establish_connection(
:adapter => "mysql",
:host => "localhost",
:username => "me",
:password => "secret",
:database => "activerecord"
)
Active Record
Data definitions are specified only in
the database.
Active Record queries the database for the
column names.
When an database object is instantiated,
attributes are created for each column
name.
next_angle.has_clients? # true
next_angle.clients_count # total number of clients
all_clients = next_angle.clients
Action Controller Features
For example:
The average code lines of code for an
action in Basecamp[1] is 5.
Look at any struts example and find any
action. It's not even funny.
Rails
Main Rails Site
• http://www.rubyonrails.org/
Installing Rails
1. Install Ruby
On Windows you can use the One-Click
installer. For other platforms, see the main
Ruby web site.
2. 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
3. Install Rails
From the command line execute:
gem install rails