搜尋

首頁  >  問答  >  主體

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

全部回覆(2)我來回復

  • 大家讲道理

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

    缺少 workcreated_email 的模板

    回覆
    0
  • ringa_lee

    ringa_lee2017-04-24 16:02:49

    要有一個view,名字大概叫workcreated.erb之類。如果用RubyMine,在controller程式碼處按Ctrl+Alt+Home會跳轉或提示建立一個

    回覆
    0
  • 取消回覆