InfoQ

News

Rails Cells: Component-Oriented Development for Rails

Posted by Mirko Stocker on May 13, 2008 04:40 PM

Community
Ruby
Topics
Object Oriented Design,
Web Frameworks
Tags
Component Based Architecture,
Rails Engines,
Rails

The aim of Rails Cells is to "bring the benefits of component-oriented development to the Ruby on Rails web application platform". A cell is a sort-of lightweight controller with an associated view that can be embedded into a website (similar to Smalltalk's web application framework Seaside).

So what's wrong with Rails' existing facilities? According to Mike Pence's blog:

Many Rails projects resort to partials with before_filters to fill the gap, but such an approach has its own problems. Shared partials bloat the application_helper with their initialization code, and since they can see all of the instance variables of the controller methods that precede them—an unfortunate design decision, I think—they tend to be rife with dependencies on the controllers that initially hosted them, the views that initially contained them, and the helpers that they depend upon. It is rare, in my experience, to find substantial partials that are readily sharable without considerable, painful, debugging to extricate them from the web of dependencies they weave.

Contrary to the relation between a controller and its view, the controller's instance variables are not automatically shared with a cell but need to be explicitly passed to it. This allows for Cells to be independent from a specific controller and therefore to be both reusable and shareable.

We talked to Nick Sutterer, one of Cells' developers, and asked him about the status of Cells' development:

We're working on an improved version of cells, but are rather busy with our daytime jobs (typical excuse for any open-source developer). Fortunately, some folks from the community have submitted patches or helped with documentation—especially Mike Pence is worth naming here. With the 1.0 release we intended to mark the plugin as useable and signalized that the API is quite stable and won't change significantly in the near future.

The next version will be fully Rails 2.0 compatible. There are some problems with helpers here. Another issue is engines [the Engines plugin enhances Rails' own plugin framework to make it easier to share controllers, helpers, models, etc. in plugins] support in cells. Personally we love engines. Great work, James. Nevertheless people seem to be afraid of it, so we have to make it optional for users. I really love the idea of putting cells into engines, it helps me to maximize the modularity of my applications. There's also a problem with the forgery protection in cells, in combination with AJAX. As cells are perfect for the use with AJAX we will spot-and-fix this in the next version. Promised.

We were also interested to hear how Cells has been adopted in the Rails community so far:

There is noteable interest for cells in the rails community. Folks come to our IRC channel or use the mailinglist regulary to ask questions about how to integrate cells into their projects. Cells introduce a new component orientation into rails - it will surely take a while till developers understand the power of it and use it in bigger applications. My co-developer Peter Bex came to cells and implemented a project called formbuilder with it. I am busy with my upcoming plugin Apotomo based on cells. It introduces stateful components in Rails. And it's hot. I'm sure there will be more noteable projects with cells. Maybe I should open a "Success Stories" blog on the cells page?

To learn more about Cells, check the Cells website or take a look at the Cells documentation.

Have you used Cells and do you have a Cells success story to tell?

1 comment

Reply

Cells and Viewlets by Kevin Teague Posted May 13, 2008 9:31 PM
  1. Back to top

    Cells and Viewlets

    May 13, 2008 9:31 PM by Kevin Teague

    "Cells make it simple to embed views within views" while the implementation details vary considerably, in Python we call "Views within Views" Viewlets. But this only makes sense since what Rails calls Controllers, we call Views. I suppose the name "Controllerlet" wouldn't get very far ...

Exclusive Content

Typemock: Past, Present and Future

Eli Lopian of Typemock answers a few questions on Typemock origins and where Typemock is headed.

Agile in Practice: What Is Actually Going On Out There?

Scott Ambler talks about actual data resulting from surveys made during 2006-2008, showing how Agile is perceived and implemented within organizations.

Building Smart Windows Applications

From QCon 2008, Daniel Moth presents on using Visual Studio 2008 and .NET 3.5 to create compelling rich Windows applications.

Joshua Kerievsky about Industrial XP

Joshua Kerievsky, founder of Industrial Logic, talks about Industrial Extreme Programming which extends XP by including practices dealing with management, customers and developers.

Jeff Barr Discusses Amazon Web Services

Amazon Web Services (AWS) Evangelist Jeff Barr discusses SimpleDB, S3, EC2, SQS, cloud computing, how different Amazon services interact, origins of AWS, AWS globalization and the March AWS outage.

More Than Just Spin (Up) : Virtualization for the Enterprise and SaaS

Cloud services have helped bring virtualization to the forefront. Its full power however, also includes other benefits such as high availability, disaster recovery, and rapid provisioning.

Ruby Beyond Rails

John Lam talks about his path to dynamic languages, some of the problems of making IronRuby run fast, and how the DLR helps with implementing languages.

VMware Infrastructure 3 Book Excerpt and Author Interview

VMware Infrastructure 3: Advanced Technical Design Guide and Advanced Operations Guide provides a wealth of practical insights into setting up virtualization in todays corporate environments.