|
|
YOUR FEEDBACK
Did you read today's front page stories & breaking news?
SYS-CON.TV |
TOP THREE LINKS YOU MUST CLICK ON FrontPage Feature
Why Ruby on Rails Has Become a Popular "Next Platform"
A RoR Primer for Java Developers
By: Ryan Garver
Dec. 4, 2007 09:45 AM
Digg This!
Page 2 of 2
« previous page
ActiveRecord associations can be specified through a bit of metaprogramming:
class User < ActiveRecord::Base The belongs_to expression in the Article class tells ActiveRecord to interpret a column from the database called user_id as a reference to the users. These constructs work in reverse as well with the has_many and has_one macros. With this knowledge, ActiveRecord can expose some interesting functionality that lends itself to writing very readable code:
article = Article.find(45)
Controllers For example, an events search page must query for a list of events and pass it up to the view. Moreover, this listing will be parameterized by some request parameters:
class EventsController < ApplicationController Rails has some syntactic sugar here for filtering client requests and handling them in different ways. These come in the form of before_filter, after_filter, and around_filter. The most commonly used filter is the before_filter:
class EventsController < ApplicationController
Views
<% form_for todo do |f| %> The CRUD philosophy mentioned above exists at this level of the framework as well. This form_for uses information from the passed in todo ActiveRecord object along with some basic conventions to build the submit method and URL for the form. The object yielded to the form block has information about the todo object. This pattern will automatically fill in default values and can be customized and extended to reflect more complex widgets or formatting. Rails is making a lot of assumptions with this form of these helpers, but the end result is a very readable piece of code that's easy to understand and maintain.
Strengths Ruby is capable of very high code density. Unlike other structured languages, developers can easily create domain-specific languages (DSL) that simplify the expression of potentially complex ideas. You can see this technique throughout Rails. ActiveRecord has macros and constructs that come across to the programmer as a micro-language specific to ORMs. The controller layer benefits from this as well. There is no language construct for a before_filter, but Rails adds something close to aspect-oriented programming (AOP) as though it's a built-in feature.
Great, Now How Do I Show the World? Automation is a strength of Ruby and there has been some early progress with tools like Capistrano, which automated much of the deployment process. But most enterprise environments require a separation between the developers and operations. Most early Rails projects didn't have a differentiation and the result was tools that required an understanding of all aspects of the application to make a deployment efficient and effective. In the last year, the JRuby project has made enormous progress in shrinking the gap when it comes to deployment. JRuby, now sponsored by Sun, is an implementation of Ruby under the JVM. A Rails application developed to run in JRuby will use JDBC as the database driver. Using a plug-in called gold_spike, a Rails application can be bundled into a .war file and be deployed onto a standard Tomcat server. Microsoft is beginning to take an interest in this as well and has started the IronRuby project (leveraging much of the work from the IronPython project) to develop a version of the Ruby interpreter that runs on the .NET common language runtime (CLR). JRuby also facilitates Java-Ruby integration. Importing a library written in Java into Ruby and using it there is trivial with this new interpreter. This has dropped many of the pre-existing barriers to Ruby and Rails adoption in the enterprise. When you have all of the code that has already been written in Java available to your Ruby code, you gain much of the programmer-friendly features of Ruby with little downside.
Where Is Rails Going? Outside of the Rails core team there's a lot of work to drive Rails into very scalable deployments and even into the enterprise. JRuby and IronRuby are a few examples of this. Some of this development has come out of the necessity of a few successful applications that have had no choice but to blaze trails in this realm. The Rails community is continuously working to find inefficiencies in the common tasks that we do as developers. Rails will continue to sand down the rough patches that appear in the development process.
References Page 2 of 2 « previous page
LATEST JAVA STORIES & POSTS
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK SPONSORED BY INFRAGISTICS
BREAKING JAVA NEWS
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||