JRuby, Ruby, Rails and You on the Cloud
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

JRuby, Ruby, Rails and You on the Cloud

  • 2,350 views
Uploaded on

Cloudstock 2010 Presentation

Cloudstock 2010 Presentation

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
2,350
On Slideshare
2,349
From Embeds
1
Number of Embeds
1

Actions

Shares
Downloads
51
Comments
0
Likes
1

Embeds 1

http://twitter.com 1

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • 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.
  • Go grab a piece of Cloud.

Transcript

  • 1. JRuby, Ruby, Rails and Youon the CloudDecember 6th, 2010
  • 2. Who am I?Hiro Asari• JRuby Support Engineer at Engine Yard• hasari@engineyard.com 2
  • 3. Engine Yard• Platform as a Service provider• Ruby on Rails specialists• http://www.engineyard.com 3
  • 4. http://thenetworkisthecomputer.com/ 4
  • 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
  • 10. Who uses Rails? 10
  • 11. Getting JRubyhttp://jruby.org 11
  • 12. NetBeanshttp://netbeans.org 12
  • 13. NetBeans (if you have it already) 13
  • 14. RubyMinehttp://jetbrains.com/ruby 14
  • 15. RVM (Ruby Version Manager)• http://rvm.beginrescueend.com/• rvm install jruby• rvm use jruby 15
  • 16. Rails ü Gets you off and running quickly 16
  • 17. 17
  • 18. jruby -S rails new cloudstock_democd cloudstock_demovi Gemfilejruby -S bundle installjruby -S bundle exec glassfish 18
  • 19. $ jruby -S rails new cloudstock_demo -m http://jruby.org create create README create app create app/controllers/application_controller.rb create app/helpers/application_helper.rb create app/mailers create app/models create app/views/layouts/application.html.erb create public create public/404.html create script/rails create test create test/fixtures create test/test_helper.rb create test/unit apply http://jruby.org apply http://jruby.org/templates/default.rb gsub Gemfile 19
  • 20. 20
  • 21. $ jruby script/rails generate scaffold user name:stringcalling init (1017e6ac0) invoke active_record create db/migrate/20101115150436_create_users.rb create app/models/user.rb invoke test_unit create test/unit/user_test.rb create test/fixtures/users.yml route resources :users invoke scaffold_controller create app/controllers/users_controller.rb invoke erb create app/views/users create app/views/users/index.html.erb create app/views/users/edit.html.erb create app/views/users/show.html.erb create app/views/users/new.html.erb create app/views/users/_form.html.erb invoke test_unit create test/functional/users_controller_test.rb invoke helper create app/helpers/users_helper.rb invoke test_unit create test/unit/helpers/users_helper_test.rb invoke stylesheets create public/stylesheets/scaffold.css 21
  • 22. $ cat db/migrate/20101115150436_create_users.rbclass CreateUsers < ActiveRecord::Migration def self.up create_table :users do |t| t.string :name t.timestamps end end def self.down drop_table :users endend 22
  • 23. Rails ü Is descriptive 23
  • 24. class User < ActiveRecord::Base validates_length_of :name, :minimum => 5end 24
  • 25. Rails ü Is tested 25
  • 26. $ find testtesttest/fixturestest/fixtures/users.ymltest/functionaltest/functional/users_controller_test.rbtest/integrationtest/performancetest/performance/browsing_test.rbtest/test_helper.rbtest/unittest/unit/helperstest/unit/helpers/users_helper_test.rbtest/unit/user_test.rb 26
  • 27. $ cat test/unit/user_test.rbrequire test_helperclass 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? endend 27
  • 28. Rails ü Is good for agile development 28
  • 29. Rails ü Makes you happy 29
  • 30. WHAT ABOUT… 30
  • 31. Accessing Java library from Rails• Generating SVG with Batik• http://xmlgraphics.apache.org/batik/ 31
  • 32. Example 1: Generating SVG with Batik require java require batik java_import org.apache.batik.svggen.SVGGraphics2D java_import org.apache.batik.dom.GenericDOMImplementation dom = GenericDOMImplementation.getDOMImplementation svg_ns = http://www.w3.org/2000/svg doc = dom.createDocument svg_ns, svg, nil svg_gen = SVGGraphics2D.new( doc ) svg_gen.set_paint java.awt.Color.send(color) svg_gen.fill java.awt.Rectangle.new(10,10,100,100) svg_gen.set_paint java.awt.Color.send(text_color) svg_gen.draw_string @user.name, 25, 55 out = java.io.StringWriter.new svg_gen.stream(out, true) render :inline => out.to_string 32
  • 33. Accessing Java library from Rails• Generating PDF with iText• http://itextpdf.com/ 33
  • 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
  • 35. JRuby on Engine Yard AppCloud 35
  • 36. JRuby on Engine Yard AppCloud — Sign up today! http://docs.engineyard.com/beta/home 36
  • 37. Testing in more detail• RSpec http://rspec.info• Cucumber http://cukes.info• Celerity http://celerity.rubyforge.org 37
  • 38. Deployment strategies•  Glassfish http://glassfish.java.net/ (.WAR)•  Tomcat http://tomcat.apache.org/ (.WAR)•  JBoss http://jboss.org/ (.WAR)•  Jetty http://jetty.codehaus.org/jetty/ (.WAR)•  Glassfish gem http://rubyforge.org/projects/glassfishgem/ (embedded glassfish)•  Trinidad https://github.com/calavera/trinidad (embedded Tomcat)•  Torquebox http://torquebox.org/ (embedded JBoss with extras)•  Google App Engine http://code.google.com/appengine/ (via google- appengine gem http://code.google.com/p/appengine-jruby/)•  Mongrel (outdated) 38
  • 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
  • 41. http://www.flickr.com/photos/10485077@N06/4975546097 41
  • 42. Thank you! Contact me hasari@engineyard.com Twitter: @hiro_asari Github: BanzaiMan http://www.flickr.com/photos/42033648@N00/372887164 42