Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 360081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:27:17+00:00 2026-05-12T12:27:17+00:00

I am trying to figure out what I am doing wrong with ActionMailer. I

  • 0

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 "laurenrothlisberger@gmail.com"  
  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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T12:27:17+00:00Added an answer on May 12, 2026 at 12:27 pm

    Try this:

    class SoldierMailer < ActionMailer::Base
    
      def welcome_email(soldier)  
        recipients soldier.email_addresses
        from "laurenrothlisberger@gmail.com"  
        subject "Welcome to the Unit"  
        sent_on Time.now 
      end
    end
    

    With this in your Soldier model: I’m assuming there is an association that contains more email addresses you want to use.

    class Soldier
    
      has_many :users
    
      def email_address
        # Results in ['primary@abc.com', 'user1@abc.com', 'user2@abc'.com]
        ([primary] + users.collect { |u| u.email }).flatten
      end
    end
    

    The key is that ‘recipients’ in ActionMailer can take an array of email addresses. Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have spent almost 24hours trying to figure out what I'm doing wrong, but
I'm trying to figure out what I'm doing wrong here, but I can't seem
Trying to figure out what I'm doing wrong when trying to put $(this) in
I'm trying to figure out what I'm doing wrong here. I'm wanting to format
I've been trying to figure out what I'm doing wrong. When it checks if
I'm trying to figure out what I might be doing wrong. This query doesn't
I am trying to figure out what I am doing wrong here. I am
I've been losing my hair trying to figure out what I'm doing wrong, let
I'm trying to figure out what i am doing wrong with action listeners. I'm
I am trying to figure out what I am doing wrong in the below

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.