Story 7 – Most Requested Features
Deploying a Ruby Application
Two decisions need to be made when deploying an applicatoin, how will you run your application in production and how will you automate deploying it to the production environment.
Easiest way to run your application
Apache’s HTTPD webserver is a nice solution, here are some links:
- Apache HTTPD (link)
- Ruby module for HTTPD (link)
- Enterprise Ruby (link)
- RailsCast on how to configure server (link)
Now that the server is configured, we should automate deployments of our app to our new server, here are some more links:
- A list of automation tools in ruby (link)
- SlideShare example using moonshine (link)
- Script example using vlad to deploy to passenger (link)
Working with Regular Expressions
Create and test your regular expressions for ruby using Rubular. Here is an example of a regex that looks for numbers and “rwanda” found in a string. In the football_predictor project under the sample directory we have an example ruby file using the regex we created in rubular.
JQuery & Ajax
Rails supports ajax using the prototype ajax library. The documentation for the rails helpers can be found here. You can can also easily replace prototype with jquery using the jrails plugin (code). We’ve installed the plugin and made the following changes to the football-predictor application to supporting deleting games using AJAX
Hint: Use the Firebug plugin for FireFox to debug and test your AJAX
SMS is easy with ClickATell in ruby. ClickATell is a pay service but you can create an account and get 10 free sms messages to start testing it.
Here are some more links to get you started:
- ClickATell Ruby Gem (link)
- Interesting Guide on sending SMS from Rails (link)
- SlideShare on using SMS in Rails (link)
- A ruby gem that allows you to connect to a USB and send messages from you laptop (link)
- A plugin that makes SMS in Rails easy (link to smsonrails)
- The above example in our football-predictor project
You can easily turn your rails application into a webservice. As an example in the football predictor application, you can now make a request to http://football-predictor.heroku.com/games.xml and get all the games in xml. To support this all we needed to was change the index action in the games controller to:
Learn more by watching this railscast ActiveResource Basics
We implemented downloading the games in the football predictor application using FasterCSV plugin. This was almost as easy as supporting xml. Here are the changes we made:
Exporting PDF is also not too hard if you use the Prawn gem (but we did not implement this in the football-predictor sample)
Rails doesn’t really do anything for database backups. How you back up your database will depend on the type of database you are using. We’ve been using MySQL which has a tool called mysqldump.
Integrating Java and Ruby
You can use JRuby which is a full Ruby interpreter that runs inside the Java JVM. With JRuby you can write ruby that calls your existing Java classes and have your Java call your Ruby classes.
There is also a way to integrate .NET with Ruby called IronRuby but it is very new and may not yet work as well. While you may want to play with this we are not comfortable recommending it for a production system.