向自己发送基本电子邮件通知

时间:2014-11-18 08:09:48

标签: ruby-on-rails ruby ruby-on-rails-4

我想做的就是向自己发送通知电子邮件。我目前不需要模板。我目前收到错误:

Template Missing

Missing template home/send_mail, application/send_mail with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in: * "/Users/bli1/.rvm/gems/ruby-2.1.3/gems/web-console-2.0.0.beta4/lib/action_dispatch/templates" * "/Users/bli1/Development/RoR/Boothie/app/views" * "/Users/bli1/.rvm/gems/ruby-2.1.3/gems/web-console-2.0.0.beta4/app/views"

路线:

match '/send_mail', to: "home#send_mail", via: "get"

控制器:

class HomeController < ApplicationController
  def index
  end

  def send_mail
    ActionMailer::Base.mail(:from => "me@example.com", :to => "myemail@gmail.com", :subject => "Contact request", :body => "test").deliver
  end

end

1 个答案:

答案 0 :(得分:2)

使用以下方法取消渲染:

 def send_mail
    ActionMailer::Base.mail(:from => "me@example.com", :to => "myemail@gmail.com", :subject => "Contact request", :body => "test").deliver
    render nothing: true
  end