How to edit a serialized array with known keys

Viewed 19

I came across this question on how to edit serialized columns in Rails, where the keys are unknown.

In my case, I want to be able to edit an array of hashes where the keys are actually known, in the serialized attribute.

An example:

class Person
     serialize :addresses
end

Where in Addresses would be an array of hashes:

{
  line_1: "1 First Street",
  line_2: "Apt 202",
  city: "Tampa",
  state: "FL",
  zip: "12313"
}

And since I would know the index of this hash within the array with the each_with_index on a show view, I want to be able to edit the information in an edit or a new form view.

0 Answers
Related