>  Q&A  >  본문

ruby - rails 发送邮件遇到问题

简单要实现的功能是:如果用户提交了一个表单,触发保存方法后就执行发送邮件通知。

controller代码:

if @work.save
        Usermailer.workcreated_email(@work).deliver_now
        format.html {redirect_to @work, notice: "Work Created"}
        format.js {}
      else
        format.html {render 'new'}
        format.js {}
      end

usermailer.rb:

class Usermailer < ApplicationMailer
  default from: "chaniel_test@163.com"

  def workcreated_email(work)
    @work = work
    mail(to: work.project.user.email, subject: "Work Item Posted")
  end
end

console 报错:

Usermailer#workcreated_email: processed outbound mail in 31.5ms
Completed 500 Internal Server Error in 127ms (ActiveRecord: 3.1ms)

ActionView::MissingTemplate (Missing template usermailer/workcreated_email with "mailer". Searched in:
  * "usermailer"
):
  app/mailers/usermailer.rb:6:in `workcreated_email'
  app/controllers/works_controller.rb:21:in `block in create'
  app/controllers/works_controller.rb:19:in `create'
天蓬老师天蓬老师2709일 전645

모든 응답(2)나는 대답할 것이다

  • 大家讲道理

    大家讲道理2017-04-24 16:02:49

    workcreated_email

    에 대한 템플릿이 누락되었습니다.

    회신하다
    0
  • ringa_lee

    ringa_lee2017-04-24 16:02:49

    workcreated.erb 또는 이와 유사한 이름의 뷰가 있어야 합니다. RubyMine을 사용하는 경우 컨트롤러 코드에서 Ctrl+Alt+Home을 누르면

    회신하다
    0
  • 취소회신하다