How To Make Arrays In YAML
Suppose you had something like the following:
schema.db
schema.db
create_table "my_things", force: :cascade do |t| t.string "tags", default: [], array: true end
MyThings need tags, and since they can have more than one, we need to save them in an array. Obviously, the first step is to add a string column and, in the migration file, make sure to set the default to an empty array (square brackets), then declare it to be an array.
In the corresponding fixture file, which is a YAML file, this can be represented the following way:
my_things.yml
one: tags: - MyString
As you can see, the contents of the array are formatted using lines that start with a single hyphen and a space, followed by the content. A multiline example follows:
my_things.yml
one: tags: - MyString1 - MyString2
For some more examples, including more complex applications, see YAML Multi-Line Arrays on Stack Overflow.