Ruby Web Frameworks: Controller Objects vs Controller Methods

After writing my blog post Introspection by Design in Ruby I was trying to think of how I might implement it with Rails’ controller methods. The idea is simple; I want to have Rails call Ruby Objects rather than methods on a Controller Object. The purpose is for pure OOP design and working with the messaging pattern.

At first glance it looks like Rails is not designed to work this way and will be very difficult to implement. Then I started thinking, perhaps other Ruby web frameworks were designed with this in mind? So after looking into it I found one: Lotus!

I’d like to discuss this aspect of different web frameworks. Anyone know of other Ruby web frameworks that have Objects for controller/view paths rather than methods?

From what I can see it’s like this:

Controller Object vs Method Per Framework

  • Rails - Methods
  • Trailblazer - Methods (Objects with Operations uses the process method on the object) (technically not a framework)
  • Ramaze - Methods
  • Lotus - Objects (uses the call method on the object for the view display)
  • Cuba - ??either??
  • Volt - ??either??
  • Sinatra - ??either??
  • Cramp - Objects (uses the start method)

Please let me know of any corrections or additions to this list!


Examples:

Lotus

class Show
  include Lotus::Action    
  def call(params)
    @article = Article.find params[:id]
  end
end

Rails

class ArticleController < ApplicationController
  def show
    @article = Article.find params[:id]
  end
end
1 Like