December 30th, 2010
With salesforce.com’s recent purchase of Heroku, Ruby just got more interesting. I’ve never dabbled in Ruby (although I’ve wanted to!) so this is an excellent reason to dig into the language and see what it’s all about. Since I’m learning Ruby I thought some people might also benefit from the experience and make the learning curve a little less steep.
So today I’m kicking off a multi-part series on getting started with Ruby and Heroku. I’m not sure how many posts there will be but I hope to post something every week on the subject. I welcome any input you might have to make my journey easier. I know there are some Ruby experts in the salesforce.com community so please keep me honest and on the right track. Here are my goals of the series:
- Learn Ruby
- Develop an app locally using Ruby on Rails and the default SQLite database
- Modify the app to use Database.com and the Force.com Toolkit for Ruby
- Deploy the app to Heroku
- Modify the app to use Database.com and the REST API
For this series I’m assuming that you have some type of basic programming background, have no knowledge of Ruby (I certainly don’t), are using a Mac (sorry PC guys/gals but most of the difference is simply setup and configuration) and have a little time to experiment and learn.
So with any new technology there is a lot of stuff to learn and digest. Here are some key aspects that you should know:
RubyGems - RubyGems is a package manager for the Ruby programming language that provides a standard format for distributing Ruby programs and libraries (in a self-contained format called a “gem”), a tool designed to easily manage the installation of gems, and a server for distributing them. You will use RubyGems to install new programs and libraries on your computer.
Ruby on Rails – RoR is an open source web application framework developed by 37Signals of BaseCamp fame. Like many web frameworks, RoR uses the Model-View-Controller (MVC) architecture pattern to organize application programming. RoR includes tools that make common development tasks easier “out of the box”, such as scaffolding that can automatically construct some of the models and views needed for a basic website. Also included are WEBrick, a simple Ruby web server that is distributed with Ruby, and Rake, a build system, distributed as a gem. RoR also uses ActiveRecord (an object-relational mapping system) for database access.
Git – Git is a distributed revision control system similar to Subversion or CVS. You don’t need Git to develop Ruby applications however I believe you will need Git to push your application to Heroku. Git is really gaining ground lately and I believe that saleforce.com is moving Code Share to github.com.
Depending on your platform, Ruby may or may not be installed already. If you are using a somewhat newer Mac then Ruby should be installed. Open Terminal and type ruby –version. You should see something like the following.
The current stable version of Ruby is 1.9.2 but I have 1.8.7 installed and it seems to be working fine for now. If you’d like to download a newer version you can do so from here. If you are on a PC, then you can use the RubyInstaller. (I actually just upgraded to 1.9.2 and followed the instructions for Snow Leopard (it was a painless intall) but there are also instructions for Leopard for those needing it.)
Now that you have Ruby installed it’s time to start getting serious. Ruby comes with a program called “Interactive Ruby” (IRB) that will show the results of any Ruby statements you provide it. Playing with Ruby using IRB like this is a great way to learn the language. To get started open Terminal and type irb. On Windows, open fxri from the Ruby section of your Start Menu.
Now for the obligatory “Hello World”. Type puts “Hello World” and hit enter. There you go. Your first Ruby program.
Dig into Ruby
Now it’s time to really dig into the Ruby language. Here are some links that I’ve found helpful in order that I would recommend.
- Ruby in Twenty Minutes – I would start with this intro first.
- Try Ruby - An interactive tutorial that lets you try out Ruby right in your browser. This is a cool tutorial but it “seemed” to crash on me a number of times.
- Ruby Tutorial – a really good tutorial for core Ruby programming
- Ruby Essentials - a free on-line book designed to provide a concise and easy to follow guide to learning Ruby.
- Ruby Koans – These are a series of files that you download and run locally to learn the language, syntax and structure.
- Hackety Hack - A fun and easy way to learn about programming (through Ruby) using the Shoes GUI Toolkit.
- Ruby Documentation – A great list of Ruby references. Pick and choose from here.
If anyone has any suggestions for other helpful sites please chime in. Spend some time using Ruby and I think next time we’ll get into Ruby on Rails.