Ruby Forum Ruby on Rails > Creating an email array based off search results

Posted by Etandrib (Guest)
on 10.04.2008 21:25
(Received via mailing list)
I'm trying to perform a search a a list of people and then create an
email based on the emails found in the result set. Any idea how to do
this? I figure this is a model topic as I need the figure out the
logic to generate an array of the emails in the results set. I'm using
the acts_as_ferret plugin and the instance variable is @volunteers
which means that the emails I need are in the instance variable
@volunteers but I don't know how to get them out of it and into the
mail_to link below - hopefully in the form of a nice method like
"volunter_emails_from_search" below.

The code to generate the email looks like the following:
[code: ruby]
<%= mail_to "#{volunter_emails_from_search}", "Email", :subject =>
"This is an example email" %>
[/code]
Posted by Danimal (Guest)
on 11.04.2008 16:51
(Received via mailing list)
Is @volunteers an array of Volunteer models, perhaps where each has
an :email attribute?

Assuming that, it's just a matter of iterating...

<% @volunteers.each do |volunteer| %>
  <%= mail_to volunteer.email, volunteer.email, :subject => "the
example subject" %>
<% end %>

The "volunteer.email" is listed twice because it's the link and it's
the display for the link.

Does that help? Or were you needing something else?

-Danimal
Posted by Etandrib (Guest)
on 14.04.2008 16:27
(Received via mailing list)
I'm actually looking to have one mail link that will mail to all the
recipients below. So if I have 5 volunteers in the search results I
can email them with a single click. Iterating just gives me multiple
email links which I can easily do with the results. This should be a
really easy thing to do I just can't figure out how to pass an array
of email address to the mail_to parameters so I have a single link
with an array of addresses.
Posted by Ar Chron (railsdog)
on 14.04.2008 17:54
Etandrib wrote:
> I'm actually looking to have one mail link that will mail to all the
> recipients below. So if I have 5 volunteers in the search results I
> can email them with a single click. Iterating just gives me multiple
> email links which I can easily do with the results. This should be a
> really easy thing to do I just can't figure out how to pass an array
> of email address to the mail_to parameters so I have a single link
> with an array of addresses.

Create a button in the view that will post back with the list of 
addressees, and have the controller call a model method to do the 
emails...  somebody somewhere will have to do the iteration, and I'd 
guess it should be the controller, unless you have a volunteer_list 
model that understands multiple volunteers.
Posted by Danimal (Guest)
on 14.04.2008 23:49
(Received via mailing list)
http://www.sightspecific.com/~mosh/WWW_FAQ/multrec.html

The problem is that there is no ideal way to include multiple
addresses in the mail_to link.

So, I see two options:

1) just use one of the "nonstandard" ways, like having a list of email
addresses separated by commas, or
2) instead of using a mail_to link, have it call an action and have
that action use ActionMailer. Then, you can specify all the addresses
you need.

If you go with option 1, just use: join(",") on the email addresses
array.

If you go with option 2, which is much better but more work, you can
pass the array in as the recipients list.

HTH!

-Danimal