ruby - rails 发送邮件遇到问题
天蓬老师
天蓬老师 2017-04-24 16:00:49
0
2
667

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

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'
天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

Antworte allen(2)
大家讲道理

缺少 workcreated_email 的模板

左手右手慢动作

要有一个view,名字大概叫workcreated.erb之类。如果用RubyMine,在controller代码处按Ctrl+Alt+Home会跳转或者提示创建一个

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!