Filters For Your Cells with cells-filters

There’s nothing like giving a quick update about “Cells”: on a rainy sunday evening. Almost a year ago we were happy “to introduce state-args into Cells”: State-args help to prevent saving state in instance variables and instead pass variables from @#render_cell@ as arguments, making your code more explicit.

One big problem was that filters couldn’t take advantage of that feature, thanks to a design flaw in Rails’ callback implementation.

h3. Example?

Consider the following call to render a freaky bassist cell.

render_cell :bassist, :play, "C-sharp", "4/4"

The cell class wants to process the incoming data in a @before_filter@.

class BassistCell < Cell::Rails
  include Cell::Filters

  before_filter :prepare

  def prepare(state, tone, timing)
    @before = "In #{tone} and #{timing}"

What now works with the new “cells-filters”: gem is that filters (here, a before filter) can receive the state-args. The implementation is very simple using the “hooks gem”: for easy peasy hooks and callbacks in Ruby.

However, we introduce a dependency to another gem, that’s why cells-filters was released as a separate gem. Go and try it! We might need to add some more behaviour to it, but please don’t ask me to completely bloat it.

You can still use the old-school filters from the Rails @Callbacks@ module but you won’t be able to retrieve state-args. I don’t feel like fixing this in the Rails core itself as “the implementation is a bit too complex”: for me.

h3. Cells Development and a Roadmap.

Dudes, Cells is getting more and more of a standard in Rails development. In the last year, 2011, we had almost “90.000 downloads”: – this is awesome! Thank you so much.

We have more plans with Cells for 2012, here’s a short summary what we’re planning.

* Get rid of the Rails dependency at all. We “already got @Cell::Base@ to use cells without a controller”: Now we want to go one step further and make cells completely decoupled from Rails. Imagine cells (and, numerous “helper” gems like formtastic) being renderable in Sinatra or without a framework at all.
* Use “tilt”: as an alternative rendering engine. The Rails rendering layer is outdated and should use an abstracting rendering gem like tilt – until we can achieve this in the core, we will provide this in cells. That’ll make huge parts of cells completely independent from Rails.
* Screencasts! Yeah, I’m working on a screencast series about cells, best practices and interesting solutions users sent in over the recent years.

Beside that, we’re permanently trying to incorporate the cells architecture into the Rails core. Let’s see where this will lead to in Rails 4.0. Happy new year, and… Cheers!


10 thoughts on “Filters For Your Cells with cells-filters

  1. I also use cells! In some projects just as a replacement for complex helpers, and in some others I use it to let clients insert bits of non-trival functionality via a WYSIWYG editor in the CMS. Cells are awesome!


  2. We use Cells in production as key component for Railsyard CMS (

    BTW is there a way in filters to access to the params passed as symbols like :user in the following example?

    @current_user %>

    That would be backward compatible with current cells implementation


  3. Sorry the example code has been escaped in the comment, I’m talking about the way we currently pass arguments to a cell like:

    render_cell :cart, :display, :user => @current_user


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s