Rails ActionMailer

问题描述 投票:0回答:1

所以我正在尝试为一个朋友建立一个简单的网站,这个朋友有一个他们为客户建立的Android应用程序的初创公司。我在RoR中构建它并且对这种开发很新。我正在联系我们表格。我已经完成了Message模型,最近为模型生成了邮件助手。遇到此错误:无法自动加载常量MessageMailer,预期/home/dmberko11/web_development/NovayTechnologies/NovayTechnologiesWebsite/app/mailers/message_mailer.rb来定义它

很困惑,为什么会这样。我将粘贴我的代码到目前为止:

message_mailer.rb

class MessageMailer < ApplicationMailer

  # Subject can be set in your I18n file at config/locales/en.yml
  # with the following lookup:
  #
  #   en.message_mailer.contact_me.subject
  #
  def contact_me(message)
     @body = message.body

     mail to: "[email protected]", from: message.email
  end
end

消息控制器:

class MessagesController < ApplicationController

 def create
  @message = Message.new(message_params)
  if @message.valid?
   MessageMailer.contact_me(@message).deliver_now
   redirect_to root_path, notice: "Message received"
  else render 'new'
 end
end

消息模型

class Message < ApplicationRecord

  attr_accessor :name, :email, :body
  validates :name, :email, :body, presence: true 
end

再说一次,我在网络开发方面是个笨蛋,但我的这位朋友对我非常耐心,他希望我在这个网站上取得成功,我正在努力为他建立。几年前我曾经这样做过,但我生气勃勃,不得不重新学习一切。欢迎任何和所有帮助!谢谢,祝你有个美好的一天

ruby-on-rails actionmailer helper contact-form autoload
1个回答
0
投票

你必须将message_mailer.rb放在正确的文件夹中:

app/mailers/message_mailer.rb

重启你的服务器。

© www.soinside.com 2019 - 2024. All rights reserved.