Ruby on rails Actionmailer传递到嵌套资源

Ruby on rails Actionmailer传递到嵌套资源,ruby-on-rails,controller,actionmailer,mailer,Ruby On Rails,Controller,Actionmailer,Mailer,我有以下几种型号 class Exam has_many :registrations end class Registration belongs_to: user belongs_to: lesson end class Lesson has_many :exam_registrations belongs_to :user end class User has_many :registrations, :through => lessons end

我有以下几种型号

class Exam 
  has_many :registrations
end

class Registration
  belongs_to: user
  belongs_to: lesson
end

class Lesson
  has_many :exam_registrations
  belongs_to :user
end

class User
  has_many :registrations, :through => lessons
end
我正在尝试设置一个自动电子邮件,每当考试更新时,就会向每个注册的用户发送一封电子邮件。我已经设置了action mailer,并为其他非嵌套资源工作,但这个特殊的案例在过去几天一直困扰着我

mailer.rb

  def inform_exam_venue(user, student, lesson, exam_registration, exam)
    @user = user
    @student = student
    @lesson = lesson
    @exam_registration = exam_registration
    @exam = exam
    mail(:to => "#{student.name} <#{student.email}>", :subject => "Exam registration update")
  end
  def update
    @exam = Exam.find(params[:id])

    @exam_registration = @exam.exam_registrations.find(params[:id])

    @lesson = @exam_registration.lesson
    @user = User.where("id =? ", @exam_registration.user_id).first
    @student = Student.where("id =? ", @exam_registration.student_id).first

    respond_to do |format|
      if @exam.update_attributes(params[:exam])
        Mailer.inform_exam_update(@user, @student, @lesson, @exam_registration, @exam).deliver
        format.html { redirect_to @exam, notice: 'Exam was successfully updated.' }
      else
        format.html { render action: "edit" }
      end
    end
  end

我的控制器代码显然是错误的,但我似乎找不到任何关于如何设置的说明。请帮助。

我在您的代码中发现的唯一错误是您在控制器中使用了

Mailer.inform_exam_update
而不是

Mailer.inform_exam_venue

因此,您需要将\u update更改为\u vention

我在代码中发现的唯一错误是您在控制器中使用了

Mailer.inform_exam_update
而不是

Mailer.inform_exam_venue
因此,您需要将\u更新更改为\u场馆