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:
<%= mail_to "#{volunter_emails_from_search}", "Email", :subject =>
"This is an example email" %>
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
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.
The problem is that there is no ideal way to include multiple
addresses in the mail_to link.
So, I see two options:
- just use one of the “nonstandard” ways, like having a list of email
addresses separated by commas, or
- 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
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.