ActiveRecord helper for serialized hashes
Posted on September 19, 2012
ActiveRecord’s serialize functionality is quite useful when you want some schema-less data within a relational database. I have found this particularly useful for two cases:
- Design elements on a page
- Authentication data for various (unknown) external services
However, the one thing that is missing from the built in functionality is the nice getter/setters that ActiveRecord provides. Let’s face it, hash syntax can be pretty annoying.
Here’s a helper I created to automagically generate attribute methods for keys in a serialized hash. There’s also a bit of functionality to interpret the data as markdown and return HTML. Enjoy!
Got something to say?