Rails: How to handle "Attribute was supposed to be a Array, but was a String" error?
From the fine manual:
serialize
(attr_name, class_name = Object)
[...] The serialization is done through YAML.
So the column should contain a YAMLized version of your image_urls
but '["image1.jpg", "image2.jpg"]'
is not a YAML array. If you want to muck around with the raw serialized data then you should use something like
["image1.jpg", "image2.jpg"].to_yaml
# ---------------------------^^^^^^^
to generate the string.
Or better, stop using serialize
altogether in favor of a separate table.
In Rails 4 it worked for me without any .to_yaml
, just added it to strong params as image_urls: []