Extra commas when iterating over @model.errors.

When the following code is run:

page.alert(@category.errors.full_messages.collect { |msg| msg + “\n” })

The following JavaScript is output:

alert(["Name is too short (minimum is 3 characters)", "Name can't be blank"]);

So, my message in the alert box looks like:

Name is too short (minimum is 3 characters)
,Name can't be blank.

The comma is on the wrong line. Any ideas on how I can get around this? I'd like to have one error per line.

Thanks in advance,

you probably want to do


which will generate

alert("Name is too short (minimum is 3 characters),\nName can't be blank")

your method is actually generating:

alert(["Name is too short (minimum is 3 characters\n", "Name can't be blank\n"])

which alert then apparently joins with a comma, ending up with what
you see in the alert dialog.