donderdag 11 juni 2009

Rails - HoboFields as Plugin

As I mentioned before, the documentation of Hobo is still not sufficient to build a real application with Hobo. One of the problems I encountered was that I wanted to change how certain fields are displayed in the new/edit form. The documentation does not describe this clearly or at all (I couldn't find it). For this Hobo is not really usable for me at this moment. One think I really like about Hobo is HoboFields though. HoboFields allows you to declare your table definitions in your model and automatically generate migrations from it. The good news is that we can actually use HoboField without using the complete Hobo package as it's available as plugin.

When HoboFields is installed you can do the following:


require 'hobo_fields'

class Category < ActiveRecord::Base
fields do
name :string
description :text
timestamps
end

belongs_to :category
belongs_to :administration
end


Next, you just run:

ruby script/generate hobo_migration


And the migration will be generated. Now you may think that this is not a good thing, because by making your own migrations you could keep track of changes and roll updates to other environments, right? Well, this is not a problem because HoboFields will actually detect any changes made to the model and generate the migrations for you!

If you are interested in using HoboFields, you can install it as follows:

gem install hobofields