Ruby heroku 服务器上的 mailgun 出错
Ruby error with mailgun on heroku server
我正在尝试使用 mailgun 在 heroku 服务器上创建一个 'contact us' 页面。我相当有信心我设置正确(我正在通过关注 upskillcources.com 来填满这个项目),但我总是收到这个错误 "We're sorry, but something went wrong."
这是似乎适用于我的 heroku 日志:
2017-05-05T06:16:10.020320+00:00 app[web.1]: WHERE a.attrelid = '"contacts"'::regclass
2017-05-05T06:16:10.020321+00:00 app[web.1]: AND a.attnum > 0 AND NOT a.attisdropped
2017-05-05T06:16:10.020322+00:00 应用程序 [web.1]:按 a.attnum 排序
2017-05-05T06:16:10.020323+00:00 应用[web.1]:):
2017-05-05T06:16:10.020344+00:00 app[web.1]: F, [2017-05-05T06:16:10.020309 #4] 致命——: [2777b122-a496-4a3d-b6b7-08b32fc56cd4]
2017-05-05T06:16:10.020377+00:00 app[web.1]: F, [2017-05-05T06:16:10.020344 #4] 致命 - : [2777b122-a496-4a3d-b6b7-08b32fc56cd4] app/controllers/contacts_controller.rb:3:在“新”中
我不知道错误日志中的代码可能有什么问题,尤其是因为我可以看到 contacts_controller.rb 文件与 github 中的相同项目代码相同多人使用同一资源提升技能资源。
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_contant_path #this should be contact path I think, but a c9 error suggested this instead and wouldn't work without the change dispite it being different than the codes on github for the same project.
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
也请让我知道我如何才能better/more具体地在这里提问,很抱歉我做起来有多么困难,这是我超越'hello world'的第一个编程项目和待办事项应用程序,非常感谢您抽出宝贵时间!
您的日志显示您的数据库中没有 table。
您需要创建和 运行 迁移。详情在这里:http://edgeguides.rubyonrails.org/active_record_migrations.html
此外,您需要记住 Heroku 默认情况下不会 运行 迁移。因此,您需要在部署代码后调用 heroku run rake db:migrate
。但是您可以通过将发布命令添加到您的 Procfile 来自动执行此过程。详细说明在这里:http://aspiringwebdev.com/run-rails-migrations-automatically-on-heroku/
我正在尝试使用 mailgun 在 heroku 服务器上创建一个 'contact us' 页面。我相当有信心我设置正确(我正在通过关注 upskillcources.com 来填满这个项目),但我总是收到这个错误 "We're sorry, but something went wrong." 这是似乎适用于我的 heroku 日志:
2017-05-05T06:16:10.020320+00:00 app[web.1]: WHERE a.attrelid = '"contacts"'::regclass
2017-05-05T06:16:10.020321+00:00 app[web.1]: AND a.attnum > 0 AND NOT a.attisdropped
2017-05-05T06:16:10.020322+00:00 应用程序 [web.1]:按 a.attnum 排序
2017-05-05T06:16:10.020323+00:00 应用[web.1]:):
2017-05-05T06:16:10.020344+00:00 app[web.1]: F, [2017-05-05T06:16:10.020309 #4] 致命——: [2777b122-a496-4a3d-b6b7-08b32fc56cd4]
2017-05-05T06:16:10.020377+00:00 app[web.1]: F, [2017-05-05T06:16:10.020344 #4] 致命 - : [2777b122-a496-4a3d-b6b7-08b32fc56cd4] app/controllers/contacts_controller.rb:3:在“新”中
我不知道错误日志中的代码可能有什么问题,尤其是因为我可以看到 contacts_controller.rb 文件与 github 中的相同项目代码相同多人使用同一资源提升技能资源。
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_contant_path #this should be contact path I think, but a c9 error suggested this instead and wouldn't work without the change dispite it being different than the codes on github for the same project.
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
也请让我知道我如何才能better/more具体地在这里提问,很抱歉我做起来有多么困难,这是我超越'hello world'的第一个编程项目和待办事项应用程序,非常感谢您抽出宝贵时间!
您的日志显示您的数据库中没有 table。 您需要创建和 运行 迁移。详情在这里:http://edgeguides.rubyonrails.org/active_record_migrations.html
此外,您需要记住 Heroku 默认情况下不会 运行 迁移。因此,您需要在部署代码后调用 heroku run rake db:migrate
。但是您可以通过将发布命令添加到您的 Procfile 来自动执行此过程。详细说明在这里:http://aspiringwebdev.com/run-rails-migrations-automatically-on-heroku/