Wrong number of arguments in my mailer?

ArgumentError (wrong number of arguments (given 0, expected 1)): app/mailers/successful_campaign_mailer.rb:4:in `successful_campaign_email’

I’m passing in a user object…

SuccessfulCampaignMailer.with(user: @user).successful_campaign_email.deliver_now

and here is my mailer…

class SuccessfulCampaignMailer < ApplicationMailer

default from: ‘no-reply@jginfosys.com’

def successful_campaign_email(user)
 @user = user

 mail(to: @user.email , subject: 'The campaign was a success...')
end

end

What did I miss?

If you want to use named variables, you have to spec them that way in your method signature.

def successful_campaign_email(user:)
  @user = user
  ...
end

Walter

ok, thanks.

I got this answer too…

SuccessfulCampaignMailer.successful_campaign_email(@user).deliver_now

that worked, and I didn’t have to change the method.

If you wanted to use with you will have to omit the argument user in your mailer action.

So basically this is how it would look like

class SuccessfulCampaignMailer < ApplicationMailer
  default from: ‘no-reply@jginfosys.com’
  
  def successful_campaign_email
    @user = params[:user]
    mail(to: @user.email , subject: 'The campaign was a success...')
  end
end

Any hash that you pass to with will be added to the params, this makes it kind of similar to how actions in controllers work.