How to edit a serialized hash in a standard rails form
Is your form working great for creating a new record, but when you use the edit function, it won’t fill the field values for the ones that are contained in your hash?
It took me awhile to find the right answer, but it was beautifully simple (as is so often the case with the right solution);
Your fields_for line should look like this:
<%= f.fields_for :whatever_your_hash_attribute_is_called, OpenStruct.new(f.object.whatever_your_hash_attribute_is_called|| {}) do |a| %>
That’s it.
Amazing, huh?
July 22nd, 2014