Frederick Cheung wrote:
> On 2 Dec 2008, at 11:27, Dave Smith wrote:
> 
>>>>> @mailinglist_mailings = @mailinglist.mailings.collect
>>> I think AJAX is an orthogonal issue - you could have a regular button
>>> or an ajax one and it wouldn't change much.
>>>
>>>
>>> Fred
>>
>> to be honest i dont really care how the emails are sent. which ever
>> method is easiest to impliment. Do you know of any examples that are
>> similar as I dont really know where to start on this one.
>>
> 
> I'm sort of struggling to see what the problem is to be honest.
> 
> if in your view you had
> 
> button_to :send_mail, :id => some_template.id, :mailing_list_id =>
> some_mailing_list_id
> 
> then your controller could be as simple as
> 
> def send_mail
>    @mail_template = MailTemplate.find params[:id]
>    @mailing_list = MailingList.find params[:mailing_list_id]
>    @mailing_list.people.each do |person|
>      Emailer.deliver_message person.email_address,
> @mail_template.subject, @mail_template.body
>    end
> end
> 
> (I'm assuming a bunch of things about which attributes and
> associations your models have but it should be quite obvious)
> 
> Fred

Thank you Fred,

It gets a little more complicated because the mailinglist has many 
mailings (database table shown below).

id     mailinglist_id       name         email_address
1         2              Dave Smith     [EMAIL PROTECTED]

So I thought you would have to collect these first then loop through 
them...

somthing like the following perhaps?

def send_mail
    @mail_template = MailTemplate.find(params[:id])
    @mailing_list = MailingList.find(params[:mailing_list_id])
    @mailinglist_mailings = @mailinglist.mailings.collect
--------- @mailinglist_mailings.mailing.each do |mailing|
      Emailer.deliver_contact(mailing.email_address, 
@mail_template.subject, @mail_template.body)
    end
    return if request.xhr?
      render :text => 'Message sent successfully'
   end

but i dont think that the line @mailinglist_mailings.mailing.each do 
|mailing| is right
-- 
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@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to