Link to home
Start Free TrialLog in
Avatar of depassion
depassionFlag for Philippines

asked on

How to pull multiple email recipients in ActionMailer - Rails

trying to pull email addresses from database:

#subscriptions_controller
def deliver
    @subscription = Subscription.find(params[:id])
    @users = @subscription.users
    @recipients = @users.find(:all).collect { |user| user.email }
    @subscription.deliver
    flash[:notice] = "Delivered Subscription"
    redirect_to subscriptions_url
  end

#subscription.rb
def deliver
  UserMailer.deliver_lotto_saturday_subscription(@user, @subscription)
  update_attribute(:schedule_delivery, Time.now)
end

#user_mailer.rb
class UserMailer < ActionMailer ::Base

def lotto_saturday_subscription(user, subscription)
  recipients  ????????
  from        "lottomail.net"
  subject     "Your Lotto Saturday Reminder"
  body       :user => user
end

ASKER CERTIFIED SOLUTION
Avatar of wesgarrison
wesgarrison
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of depassion

ASKER

Hi Wes,thanks for answering. I get the following error:


Processing SubscriptionsController#deliver (for 127.0.0.1 at 2009-12-22 01:21:49) [POST]
  Parameters: {"authenticity_token"=>"VqXdHq+XSM0LAjjkuxau3g/rwUz6aGUyk9xzEk906Gs=", "id"=>"1"}
  Subscription Columns (1.6ms)   SHOW FIELDS FROM `subscriptions`
  Subscription Load (0.2ms)   SELECT * FROM `subscriptions` WHERE (`subscriptions`.`id` = 1)
  subscriptions_users Columns (1.2ms)   SHOW FIELDS FROM `subscriptions_users`
  User Load (1.0ms)   SELECT * FROM `users` INNER JOIN `subscriptions_users` ON `users`.id = `subscriptions_users`.user_id WHERE (`subscriptions_users`.subscription_id = 1 )
  User Columns (0.9ms)   SHOW FIELDS FROM `users`

ArgumentError (wrong number of arguments (1 for 0)):
  app/controllers/subscriptions_controller.rb:12:in `deliver'
  app/controllers/subscriptions_controller.rb:12:in `deliver'

Rendered rescues/_trace (56.5ms)
Rendered rescues/_request_and_response (0.5ms)
Rendering rescues/layout (internal_server_error)
Whoops:
#subscription.rb
def deliver(recipients)
  ....

Open in new window

Thats it, thanks!
Sorry, I was just typing off the cuff, not actually running it, and I changed that method.