Rails & Ruby's answers to the Java world

Steve Robinson

4 min read

We recently are dealing with a company which specializes in building enterprise Java applications. When we proposed to use Rails for a couple of applications they had a lot of doubts and questions. But Rails had a solution or answer to every single issue that was raised and our client was pretty convinced. We thought of sharing those questions here on our blog. So here they are.

javaruby
1. Is it possible to securely deploy a Rails application’s code locally at the customer’s site?
Our client did not want a cloud hosted solution for a certain product and wanted to be able to deploy the code directly at their customers’ site. They wanted to secure the code so the customers would not be able to make changes and break things. The most basic and easiest solution for this would be to have a strong End User License Agreement (EULA) that defines what can and cannot be done. But even with this in place we cannot be sure that our code would not be meddled with. So after a bit of research we found a really sophisticated tool called RubyEncoder. This software encrypts Ruby projects in a way that the encrypted ruby files cannot be reverse engineered to obtain the original code. In addition to this basic protection, it offers an array of features like restricting the application to a specific MAC or IP address and domain, distributing the application as a Trial version and support for offering a sort of license key to unlock the full version, etc. This is a solid commercial solution that could be used to protect a Rails Application. One more way would be to use JRuby instead of the MRI Ruby (or just Ruby as it is popularly known) and compile the ruby files to bytecode and thereby preventing any unwanted modifications to the code.
2. Does Rails have an ORM? Can we use enterprise DBMS like Oracle and DB2 with Rails?
If you are a Rails developer, you would know the answer. But if you’re not, Rails uses an ORM called ActiveRecord to encapsulate whatever database that you may decide to use. So ActiveRecord is your Hibernate counterpart in Rails. Popularly Rails developers use MySQL and PostgreSQL databases. Both are quite powerful and capable enough to handle significant loads. But if you really need the extra features and tools provided by those so called ‘enterprise’ databases like Oracle, DB2, SQL Server etc., you can just swap out the MySQL or PostgreSQL adapters for adapters written for the database you need. For example, if you want to use Oracle, you would use the ‘oracle_enhanced‘ adapter which is available as a Ruby Gem (more on this later). Its as simple as that. ActiveRecord will take care of the rest. ActiveRecord is not the only ORM available for a Ruby based application. There’s DataMapper, Sequel etc. But ActiveRecord is more mature and popular and comes as part of Rails and hence highly supported and in active development. Rails as a framework is completely database agnostic.
3. How to expose the application’s functions as web services (in other words, how to expose an API)?
This is one of the most simplest things to do in Rails. In fact Rails’ scaffolding exposes a JSON REST API by default! Exposing an API is a simple one liner. You could just do render json: @product at the end of a controller action and it will return the ‘@product’ object serialized in the JSON format as response. If you want to respond with either JSON or HTML or maybe with XML depending upon the request, you can use the following block.
[source language=”ruby”]
respond_to do |format|
format.html
format.xml { render xml: @product.to_xml }
format.json { render json: @product }
end
[/source]
This will respond with the appropriate format based on the request. Its that simple to do this kind of stuff in Rails.
4. Is it possible to visualize data in Rails?
Well, this isn’t something Rails is meant to do. Rails can provide data in whatever format you need and you can use it with your JavaScript libraries to create charts, graphs etc. This question is a nice place to point out that Rails is also JavaScript Framework agnostic as of Rails 3.0. What this means is, you can use any JavaScript framework you like (JQuery, Prototype, ExtJS etc). So you can use any kind of JavaScript library to do visualizations. Famous libraries include HighCharts, Flot, D3, etc. If you do not want to use JavaScript, you can always go for tools like GraphViz, etc. The point here is with Rails, you can plug any client-side library in and do your magic.
5. Can Rails work with PDF, MS Word, MS Excel documents?
Yes! They can absolutely work with those documents. There is an amazing set of Gems to support this. Prawn is a pretty sophisticated library for dealing with PDF documents. You have the Spreadsheet gem for Excel and other spreadsheet documents. There isn’t a solid gem yet for MS Word support. But since all Microsoft Office files have the Open XML format, you can easily create a template in MS Word and export it to XML, and use it as a template in Rails to generate Word Documents.
6. Does Rails have Wiki libraries?
Yes it does. A lot of them infact. If you can check this link out, you will see the immense number of options available for you to integrate a Wiki in your application (although only the first few are trustworthy and relevant).
7. Is there a list of third party libraries available for use with Rails?
Okay, You have seen the use of the word Gem everywhere in this post. For those who donot know what a gem is, it is a bundle of Ruby classes that help developers to perform some task. They are just libraries that you can integrate into your application. They are similar to the libraries you use in Java. Gems are hosted publicly by RubyGems.org. Most developers refer to www.ruby-toolbox.com when they want to find a certain gem. It lists gems grouped into categories and provides ratings based on popularity and downloads, development activity level, links to documentation, official website etc. You will find loads of gems here.
8. Can a Ruby on Rails application be deployed under JBOSS, Weblogic or Tomcat containers?
All these servers are build for the JVM. The Ruby most of us use, the MRI Ruby, does not run on the JVM. But we do have other implementations of the Ruby language that use a compiler to compile the Ruby code before execution. The most popular ones are JRuby (JVM), IronRuby (.NET) and Rubinius (Rubinius Virtual Machine). So if we use JRuby, we could easily deploy our Rails applications into these Java Application Servers.

Related posts:

Leave a Reply

Your email address will not be published. Required fields are marked *