Hi I am trying to figure out what I am doing wrong with ActionMailer. I need to be able to pass more than one argument to a mailer but continue to receive the error "wrong number of arguments (1 for 2)".
My code is: soldier_controller
def create
@soldier = Soldier.new(params[:soldier])
@battalion = Battalion.find(params[:battalion_id])
@company = Company.find(params[:company_id])
@frg = @company.users.find_by_position('FRG Leader')
respond_to do |format|
if @soldier.save
flash[:notice] = 'Soldier was successfully created.'
format.html { redirect_to battalion_company_soldier_path(@battalion, @company, @soldier)}
format.xml { render :xml => @soldier, :status => :created, :location => @soldier }
else
format.html { render :action => "new" }
format.xml { render :xml => @soldier.errors, :status => :unprocessable_entity }
end
end
end
soldier_mailer.rb:
class SoldierMailer < ActionMailer::Base
def welcome_email(soldier, primary)
recipients soldier.primary.email
from "[email protected]"
subject "Welcome to the Unit"
sent_on Time.now
body
end
soldier_observer.rb:
def after_create(soldier, primary)
SoldierMailer.deliver_welcome_email(soldier, primary)
end
Basically I need to send this same email to several different recipients whose email addresses are in models all associated with the Soldier model. I have no problem sending an email to when there is just one parameter in the method. If I add more than one it throws that error.
I would appreciate any help or guidance.
Thanks.