Heroku 500内部服务器错误,TypeError(没有将Symbol隐式转换为Integer):

时间:2017-07-06 12:14:02

标签: ruby-on-rails heroku mailgun cloud9

第一次发帖。 我试图让mailgun给我发新电子邮件给新用户 但是当我填写表单时,它会给我500个内部服务器错误和TypeError。

错误日志

  

在13ms内完成500内部服务器错误(ActiveRecord:4.9ms)   TypeError(没有将Symbol隐式转换为Integer):
  app / controllers / contacts_controller.rb:9:在[]' app/controllers/contacts_controller.rb:9:in创建'

我的ContactsController有什么问题吗?

class ContactsController < ApplicationController
 def new
@contact = Contact.new
end

def create
 @contact = Contact.new(contact_params)
 if @contact.save
  name = params[:contact][:name]
  email = params[:contact][:email]
  body = params[:contact][:comments]
  ContactMailer.contact_email(name, email, body).deliver
   flash[:success] = "Message sent."
   redirect_to new_contact_path
 else
   flash[:danger] = @contact.errors.full_messages.join(", ")
   redirect_to new_contact_path
 end
end  

 private
    def contact_params
     params.require(:contact).permit(:name, :email, :comments)
    end  
end

contact_email.html.erb

   <!DOCTYPE html>
   <html>
     <head></head>
     <body>
       <p>You have received a message from the site's contact form, from
       <%= "#{ @name }, #{ @email }." %></p>
       <p><%= @body %></p>
     </body>

   </html>

奇怪的是,如果我通过cloud9服务器在开发中运行我的代码它运行正常但是在生产中通过heroku服务器它在尝试提交完全填写的联系我们表单后给我一个错误。 我也正在学习如何按照website进行编码。 问题在于第78课。

1 个答案:

答案 0 :(得分:-1)

姓名,电子邮件,正文 - 必须是字符串。

inspect it by 
name.class
email.class
body.class

ActionMailer只能使用基本类型(比如字符串),但是在代码中,名称,电子邮件,正文中的某个人是符号类。