Search code examples
ruby-on-railsrubymailer

Rails mailer error: wrong number of arguments (1 for 2)


Controller

  def mail_test
    @user = User.all.first
    @course = Course.all.first
    examplemailer.student_reminder(@user, @course).deliver
    redirect_to '/'

  end

Mailer controller

  def student_reminder(user, course)
    @user = user
    @course = course
    @url = 'http://www.google.com'
    mail to: @user.email, subject: "Good Job!"
  end

Here, I need to use <%[email protected]%> and <%= @course.title%>.

However, that code doesn't work, ending in the error

ArgumentError in Rails::MailersController#preview wrong number of arguments (1 for 2)

at

 def student_reminder(user, course)

I think I have proper number of arguments (user and course)


Solution

  • As noted above, the error was in the MailerController#preview method.