"私人方法`new'呼吁消息:Class"

时间:2018-04-18 22:07:06

标签: ruby-on-rails ruby

我在messages_controller中有以下代码:

class MessagesController < ApplicationController
    def new
        @message = Message.new
    end

  def create
    @message = Message.new message_params

    if @message.valid?
      MessageMailer.contact_me(@message).deliver_now
      redirect_to new_message_url, notice: "Message received, thanks!"
    else
      render :new
    end
  end

 private

 def message_params
    params.require(:message).permit(:name, :email, :body)
  end  
end

但我一直收到错误&#34;私人方法&#39;新&#39;呼叫消息:Class。&#34;每当我尝试加载显示消息表单的页面时(route:/ messages / new)。据我所知,新的不是私人方法吗?任何帮助将在此错误中受到赞赏!

我的邮件程序类看起来像这样:

class Message < ApplicationMailer

  def contact_me(message)
    @body = message.body

    mail to: "EMAIL@gmail.com", from: message.email
  end
end

编辑: 我已经包含了我的消息模型

class Message
    include ActiveModel::Model
    attr_accessor :name, :email, :body
    validates :name, :email, :body, presence: true
end

0 个答案:

没有答案