SMERF and issues with MySQL
SMERF is the meta form generator plugin for Rails. The plugin I would say is very useful. It takes in a form definition file, defined in YAML and creates a form on the fly. These forms are associated to users and the responses to the forms are also persisted in the db. Ideal for making a quick survey for the users on your websites. I was using this plugin to create a survey for the upcoming fashion website chictini.com, and ran into a weird issue.
SMERF plugin, actually parses a form definition YAML file, and creates a SmerfForm object out of it. This SmerfForm object is actually persisted in your db, for fast future accesses. Now this SmerfForm object is serialized into a text field in a MySQL table. Everything works fine when you have small forms. But as soon as your forms get bigger, you hit a MySQL issue. The max size of a text field in MySQL is 64 KB. So if the serialized data is more than 64 KB, you start getting weird errors. The serialization does nnot throw an error, neither does saving the object in DB. But when you try to access the serialized data, you basically get incomplete serialized data, which is nothing but garbage for your purposes.
Solution: Change the column which stores the serialized data to longtext for MySQL. You can create a migration for this which would look like this:
class UpdateColumnInSmerf > ActiveRecord::Migration def self.up execute "ALTER TABLE smerf_forms MODIFY COLUMN cache LONGTEXT" end def self.down execute "ALTER TABLE smerf_forms MODIFY COLUMN cache TEXT" end end
This was was one of the annoying issues which kept me awake till 3 am.
