Goldberg, the web framework for Rails

I’ve been in need of a quick starting platform for a small job I’m doing in London (while I find my feet and hunt around for a more permanent job).

Rails has been the obvious answer, being fast and cheap to implemement, as well as being the language-de-jour, but for a even faster start have a look at the Goldberg framework.

Goldberg (unfortunate name) is a membership kit framework built on Rails, and is delivered as a Ruby Gem, making it very easy to setup with a simple gem command…

gem install goldberg_generator

Goldberg is a few things; a membership kit (providing methods for authentication, registration, forgotten password, etc), a very basic CMS and menuing system, and admin scaffolding.
This sort of thing should sound familiar to .NET boffins at least, with projects like the MVC Membership Starter Kit doing the same stuff.

While it’s a very easy way to get a lot of the boiler plate code for free there are still a few issues with the current version of Goldberg and that means you’ll need to massage it to suit the shape of your site and requirements.

Here’s one little tip that I’ve come up with: to keep a clean upgrade path we want to avoid changing any of the code under the /$RAILSPROJECT/vender/plugins/goldberg/ directory, naturally.

But we also want to be able to modify certain aspects to suit our liking. For instance, the current menu’ing system is quite clumsy; it uses a controller to do the redirections, meaning all menu links are prefixed with the controller name, as per standard Rails routing; so I wanted to customise the view template.

To do this I have to point the Helper method’s render call to my own version of the template file (/$RAILSPROJECT/app/views/goldberg/menu_items/_suckerfish.rhtml – opposed to the original /$RAILSPROJECT/vendor/plugins/goldberg/app/views/goldberg/menu_items/_suckerfish.rhtml).

Thanks to Rails dynamic nature, that’s quite easy to do. Simply add something like the following to the bottom of your application.rb file:


  # Point Goldberg to our template files for some things
  Goldberg::Helper.class_eval do
    def goldberg_suckerfish_menu
      render :file => "#{RAILS_ROOT}/app/views/goldberg/menu_items/_suckerfish.rhtml", 
            :use_full_path => false, :locals => {:items => Goldberg.menu.get_menu(0)}
    end
  end

Simple. This code is basically just intercepting the Goldberg::Helper class method definition, and overwriting it with new code to render from the correct directory.
You should be able to do the same thing for classes, setting the class’s template_root parameter to your custom path.


About this entry