Is there a way to do that in a single shot? Or what's the most efficient way of doing that? I've researched a lot but did not find out how to do it yet. Any help will be much appreciated.
Example (the syntax is not correct is some cases):
- Models: User belongs_to :group Group has_many :users
- Controller: #User columns: id, email, group_id, etc. @users = User.find(:all, :order => "group_id")
#Things I wanted to have: #@emails1 = array of all emails, i.e. [email_1,email_2, etc] #@emails2 = string with all emails joined, i.e. "email_1,email_2,email_3,etc" #@emails3 = hash/map with all emails grouped by group_id, i.e. [group_id_1 => [email_1,email_2], group_id_2 => [email_3,email_4,email_5],etc]
- View: <%= mail_to 'me@yahoo.com', 'Email Everybody 1', :subject => 'Subject', :bcc => @emails1.join(',') %> <%= mail_to 'me@yahoo.com', 'Email Everybody 2', :subject => 'Subject', :bcc => @emails2 %> <%= mail_to 'me@yahoo.com', 'Email Group ' + @group_id, :subject => 'Subject', :bcc => @emails[@group_id].join(',') %> etc