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, Ryan -- Ryan Prins rprins-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org http://www.lazyi.net --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
> 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"]);The collect method returns an array, so you are passing an array to alert. I think you want join, which will return a string: page.alert(@category.errors.full_messages.join("\n")) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
you probably want to do page.alert(@category.errors.full_messages.join(",\n")) 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. Chris On 8/30/06, Ryan Prins <rprins-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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, > Ryan > > > -- > Ryan Prins > rprins-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > http://www.lazyi.net > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---