5. WHAT IS RUBY ON RAILS?"
AND"
WHY RUBY ON RAILS?
http://www.flickr.com/photos/88019192@N00/3277925689/
5
6. JVM Web Frameworks Surveys
• http://bit.ly/jvm-frameworks-matrix
• http://bit.ly/webmatrixsurveyresults
6
7. Rails
ü Is a web application
framework written in Ruby
http://www.flickr.com/photos/46799485@N00/4386602878
7
8. Ruby quick facts
• Conceived by Yukihiro
Matsumoto (a.k.a. Matz)
in 1993
• Object-oriented
dynamically-typed
interpreted scripting
language
• Influenced by Perl,
Smalltalk, Eiffel and LISP
• External libraries are
most frequently
distributed as “gems”
8
9. Rails quick facts
• Conceived by David
Heinemeier Hansson
(a.k.a. DHH) in 2004
• Extracted from 37signals’
“Basecamp” application
• Uses MVC design
pattern
• Rails 3, released in
August, 2010, uses
“Bundler” to manage
gems.
9
27. $ cat test/unit/user_test.rb
require 'test_helper'
class UserTest < ActiveSupport::TestCase
test "bare user is invalid" do
u = User.new
assert !u.valid?
assert u.errors[:name].any?
end
test "user with name shorter than 5 character is invalid" do
u = User.new(:name => "hi")
assert !u.valid?
assert u.errors[:name].any?
end
test "user with name with at least 5 character is valid" do
u = User.new(:name => "hello")
assert u.valid?
end
end
27
34. Example 2: Generating PDF with iText
require 'iText-5.0.5'
pdf = com.itextpdf.text.Document.new
para = com.itextpdf.text.Paragraph.new "Hello #{@user.name}"
file = "#{::Rails.root.to_s}/tmp/pdfs/pdf_demo.pdf”
out = java.io.FileOutputStream.new file
com.itextpdf.text.pdf.PdfWriter.get_instance pdf, out
pdf.open
pdf.add para
pdf.close
render :file => file
Don’t do this in production code!
34
39. Further information
• The Ruby language web site http://ruby-lang.org
• Ruby On Rails web site http://rubyonrails.org
• JRuby web site http://jruby.org
• Engine Yard web site http://engineyard.com
• Using JRuby (Pragmatic Bookshelf)
http://www.pragprog.com/titles/jruby/using-
jruby
• Meet Rails 3 (Peep Code)
https://peepcode.com/products/meet-rails-3-i
39
40. Zero to Rails 3
• http://www.engineyard.com/sparkle
• 4-day online training (December 20-23)
40
Once upon a time, there was a company which declared that “The Network Is The Computer”.These days, it is impossible to think of a computing environment without the network.
At Devoxx 2010, Matt Raible surveyed the current status of JVM Web application frameworks.Ruby on Rails (via JRuby) came in #3 of 13 surveyed.Factors considered:Developer ProductivityDeveloper PerceptionLearning CurveProject HealthDeveloper AvailabilityJob TrendsTemplatingComponentsAjaxPlugins or Add-OnsScalabilityTestingi18n and l10nValidationMulti-language Support (Groovy / Scala)Quality of Documentation/TutorialsBooks PublishedREST Support (client and server)Mobile / iPhone SupportDegree of RiskAfollowup survey by another http://sebastien-arbogast.com/2010/11/19/jvm-web-framework-survey-first-results/From a small sample size, Rails came out #1.But really, you need to see for yourself if Rails (or any other Web application framework) works for YOU!
“Convention over configuration”
The original implementation of Ruby (also called CRuby, or MRI—Matz’s Ruby Interpreter) is implemented.A newer implemenation of the language, such as JRuby and Rubinius, can compile Ruby programs into byte code to execute them.
Blog in 15 minutes: http://www.youtube.com/watch?v=Gzj723LkRJY
The list might be outdated.Backpack (37 Signals)Cookpad (Recipe sharing site in Japan)Get Satisfaction (Customer service helper)Github (Social code sharing)Hulu (Online video streaming)Oracle Mix (SNS for Oracle professionals)New York Jets (J. E. T. S. Jets, Jets, Jets)Pragmatic BookshelfGrouponLighthouse (Development issue tracker)ZenDesk (Customer Support ticket tracker)
http://jruby.org/download1.5.6 was released last Friday (Dec. 3, 2010)1.6 coming later this month or early next year
NetBeans
You can install and activate Ruby and Rails plugin if you have NetBeans already. (6.9 and later supports Rails 3.)
RubyMine
“Convention over configuration”In web application development, there are a lot of things that happen over and over.(Setting up MVC, configuring Database connections, laying out directory structures, etc.) Rails aims to make sensible decisions for you, so that you don’t have to make these decisions.You might think it’s constraining at first, but you will soon learn that by allowing you to spend more time thinking about the application itself (rather than “administrivia”) Rails liberates you.
These are the commands used in the previous video.
It creates a lot of directories and files with boilerplate content.Give -d mysql to use MySQL as the database engine.
It creates a lot of directories and files with boilerplate content.
Database schema modification is described in Ruby as well.This migration file was generated by the scaffold generator.
Rails can be described as a DSL for web application development.
It is clear what this piece of code does.
Testing is a part of Ruby and Rails culture.
Scaffold generator that we ran earlier also created a few files for tests as well.
You *could* add test code such as this.You won’t have to test “validates_length_of” in this way, since it is a part of Rails, and, as such, it is very well tested and understood.
Here, “agile” means short feedback cycles
The bottom line is that Rails makes you happy.
JRuby is an implementation of the Ruby language on the JVM. It can interoperate with the vast collection of existing Java libraries.http://vimeo.com/16270284 http://trackernet.org
*DEMO 1*
This example generates a simple SVG graphics with Batik library. http://xmlgraphics.apache.org/batik/
*DEMO 2*
This example generates a PDF file through iText. http://itextpdf.com/This is for illustration purposes only. It is not very secure, not is it very scalable.
If you’re interested, sign up to be notified.
What we did not cover today
What we did not cover today:WAR files are created through warbler gem. http://kenai.com/projects/warbler/pages/HomeTorquebox’s (http://torquebox.org) extras include:ActiveMQ and built-in job scheduling supporthttp://jruby-appengine.blogspot.com/
Engine Yard is offering an online training course of Rails 3 later this month.