Why Ruby?Ruby is…A dynamic, open source programminglanguage with a focus on simplicity andproductivity. It has an elegant syntax that is naturalto read and easy to write.
WHY SHOULD YOU SWITCH TO RUBY? IF YOU ARE HAPPY WITH PERL OR PYTHON, YOU DONT HAVE TO. BUT IF YOU DO FEEL THERE MUST BE A BETTER LANGUAGE, RUBY MAY BE YOUR LANGUAGE OF CHOICE. LEARNING A NEW LANGUAGE IS HARMLESS. IT GIVES YOU NEW IDEAS AND INSIGHTS. YOU DONT HAVE TO SWITCH, JUST LEARN AND TRY IT. YOU MAY FIND YOURSELF COMFORTABLE ENOUGH WITH RUBY TO DECIDE TO SWITCH TO IT. -- YUKIHIRO MATSUMOTO (“MATZ”) HTTP://LINUXDEVCENTER.COM/PUB/A/LINUX/2001/11/29/ RUBY.HTML
Concurrency is a Myth HTTP://WWW.IGVITA.COM/2008/11/13/CONCURRENCY-IS-A-MYTH-IN-RUBY/
ILYA GRIGORIK HTTP://WWW.IGVITA.COM/ABOUT/ JRUBY IS, IN FACT, THE ONLY RUBY IMPLEMENTATIONTHAT WILL ALLOW YOU TO NATIVELY SCALE YOUR RUBY CODE ACROSS MULTIPLE CORES. BY COMPILING RUBY TO BYTECODE AND EXECUTING IT ON THE JVM, RUBYTHREADS ARE MAPPED TO OS THREADS WITHOUT A GILIN BETWEEN - THATS AT LEAST ONE REASON TO LOOK INTO JRUBY. HTTP://WWW.IGVITA.COM/2008/11/13/CONCURRENCY-IS-A-MYTH-IN-RUBY/
Install JRuby (via rvm)rvm install jruby-1.6.3When it’s done, use it: rvm use jruby-1.6.3List of other ruby versions to install: rvm list knownList versions of ruby you have installed: rvm list
JRuby Without RVMAssume Java, JRuby in your pathjruby -S gem ...
Install Railsgem install railsCan pick a speciﬁc version with a“-v” ﬂag.
Create Your Rails AppJruby.org hosts a rails template Sets things up to run under native ruby or JRuby You can do this yourself, but it’s handier to start this wayrails new uberconf_demo --template=http://jruby.org Works with native ruby or JRuby.
Packaging Your App http://en.wikipedia.org/wiki/File:Distribution_differences.jpg
JRuby/Rails/WAR ﬁlesIn the Java world, WAR ﬁles are standardFortunately, we have bundler Gem to package your Rails app as a WAR ﬁleCan even make it “Executable” for stand-alonetesting!http://caldersphere.rubyforge.org/warbler/
Run It http://en.wikipedia.org/wiki/File:Jeanette_Kwakye_cropped.jpgEasy!warble war
Other Useful Optionswarble compiled # Feature: precompile all Ruby ﬁleswarble conﬁg # Generate a conﬁguration ﬁle to customize your archivewarble executable # Feature: make an executable archivewarble gemjar # Feature: package gem repository inside a warwarble pluginize # Install Warbler tasks in your Rails applicationwarble version # Display version of Warblerwarble war # Create the project war ﬁlewarble war:clean # Remove the project war ﬁlewarble war:debug # Dump diagnostic information
MavenIn the Java world, Maven is still pretty popular For better or for worseYou can use Maven to invoke warbler to packageyour app.
Database MigrationsRails uses Rake for ActiveRecord migrationsNice, but Hard to scale to multiple developers Hard to deploy to QA/Production systems without using ruby toolset Paranoid DBAs can’t see the SQL before running it.
Enterliquibase.orgVersion control for your databaseOther frameworks (Grails) will be adopting it formigrationsLanguage/Database agnostic.
LiquibaseNothing special about using Liquibase with RailsUse ActiveRecord migrations for initial dev/testing,then migrate to LiquibaseWhen ready, just take “snapshot” of DB conﬁg,then roll out new Liquibase changesets.
Handy Liquibase CommandsGenerate initial changelog:java -jar liquibase.jar --classpath=mysql-connector-java-5.1.14-bin.jar --url=jdbc:mysql://localhost/api_development --driver=com.mysql.jdbc.Driver --username=demo --password=password --changeLogFile=db-changelog.xml generateChangeLogDrop all tables so you can start over:dropAllRun updates against a DB:liquibase --changeLogFile=myChangeLog updateJust output SQL, don’t run: updateSQL
Servlet FiltersYou’ll need a custom web.xml conﬁgCopy WARBLER_HOME/web.xml.erb to conﬁg/web.xml.erb Look for it at ~/.rvm/gems/jruby-1.6.2/gems/ warbler-1.3.1/web.xml.erb HTTP://EN.WIKIPEDIA.ORG/WIKI/FILE:DICHROIC_FILTERS.JPG
Set Root Path for AppBy default, the root of your app is the WAR nameThis may not be what you want.
Set the Root PathCreate ﬁle jboss-web.xml in root of app directoryTell warbler to include it via warble.rb
Bundle Up Files into AGemCan be much faster to build/deploy depending onhow you do it (there are a lot of ﬁles!)Make sure to test it
Make Your War ExecutableCommand Line:warble executable war In warble.rb: conﬁg.features = %w(executable)
Rails ConsoleRails has a “Console Mode” for testingGreat for trying out ActiveRecord queries, etc.Just use “rails console” to invoke it.
Gem VersionsBe sure to lock down Gem versions when you’rehappy with themDon’t want any last minute “upgrades!”Use bundlerPut Gemﬁle.lock under source control.
Basic Versioning RulesAfter bundling, always check your Gemﬁle.lockinto version controlAfter updating your Gemﬁle, always runbundle install ﬁrst.When running an executable, ALWAYS usebundle exec [command] The only exception is the rails command!http://yehudakatz.com/2011/05/30/gem-versioning-and-bundler-doing-it-right/
Handle Database Connection OutageThis is the “default” 500 error page.