Re: Each returns just last array

Robert Walker
Wed, 15 Feb 2012 02:22:18 -0000

Felipe Pieretti Umpierre wrote in post #1046832:

Maybe you wanted....

> emails_controller.rb

@a = []

> emails.each do |e|
>
>       for_each_one = e.split( "," )

         @a << for_each_one

Append split array to @a array. (i.e. an array of arrays).

>
>       #@email.name = for_each_one[ 0 ]
>       #@email.email = for_each_one[ 1 ]
>       #@email.save
>       #
>       #if @email.valid?
>       #  @group.emails << @email
>       #end
>
>     end
>
> action
>
> <% @a.each do |a| %>
> <%= a[0], a[1] %>

The .each here would yield the two arrays contained within the outer
array.

> <% end %>
>
> return :
>
> myemail-4cajJJ5tN1zQT0dZR+AlfA@public.gmane.org
> My Name
>
> Thank you.

I''m not sure if that''s exactly what you wanted, but should
point you in
the right direction.