InfoQ

News

Rails Cells: Component-Oriented Development for Rails

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

Community
Ruby
Topics
Web Frameworks ,
Object Oriented Design
Tags
Rails Engines ,
Component Based Architecture ,
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?
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 ...

Educational Content

Bindings, Platforms, and Innovation

This presentation focuses on the Internet and separating myth from fact, history from the future, and the mundane from the imaginative. Bob Frankston presents a vision of what could and should be.

Orchestrating Long Running Activities with JBoss / JBPM

This article explores the use of JBoss and jBPM to implement design solutions that effectively address the issue of orchestrating long running activities.

Neo4j - The Benefits of Graph Databases

This presentation covers the use of graph databases as an optimal solution for data that is difficult to fit in static tables, rapidly evolving data or data that has a lot of optional attributes.

Realistic about Risk: Software development with Real Options

This session introduces Real Options and shows how it can help in running your project. Real Options is a decision-making process that can be used to manage risk.

Communication Flexibility Using Bindings

This article discusses the use of bindings on services and references (including the instance of non-configured bindings) as the means to implement SCA communications in a Web and SOA environment.

Writing DSLs in Groovy

After a short introduction to DSLs, Scott Davis plays with the keyboard showing how to approach the creation of a DSL by typing working snippets of Groovy code that get executed.

Scaling Agile with C/ALM (Collaborative Application Lifecycle Management)

IBM Rational and InfoQ present, Scaling Agile with C/ALM, an eBook showing organizations how to become “finely tuned software delivery machines” by enabling team integration and scaling.

Concurrent Programming with Microsoft F#

Amanda Laucher presents a real life enterprise application written in F#. She shows actual code snippets, explaining design decisions and suggesting how to use some of the F# constructs.