Category Archives: rails

visualize state_machine’s with graphviz

The guys at Plugin-a-week have written a nice ActiveRecord state machine gem called state_machine. One of the great things about state machines is that they often can be visualized. To that end I’ve written a small utility that will load a class that uses state_machine and produce dot output which you can use with graphviz. This [...]
Also posted in programming, ruby | Leave a comment

ActiveRecord from_xml (and from_json) part 2

This post is an upgrade to the previous post about the unmarshalling of XML and JSON strings into rails objects, with arbitrarily deep object associations. As you may know if you are reading this, there doesn’t seem to be a way in rails to reverse to_xml and to_json when associations are included. Example usage: xml = firm.to_xml [...]
Also posted in programming | Tagged , , , , , | 3 Comments

ActiveRecord from_json and from_xml

Unless I’m missing something, the default rails from_json and from_xml methods don’t work with data that have associated objects. Here are routines that work for some simple examples I’ve tested. I placed this code in vendor/rails/activerecord/lib/active_record/base.rb within the ActiveRecord::Base class, but there might be a better place to put it. def self.from_hash( hash ) h [...]
Also posted in programming | Tagged , , , , , | 4 Comments