我正在尝试在heroku上部署一个小应用程序。部署工作正常,它在我的本地环境中运行没有问题。但是,在生产中,应用程序立即崩溃,引发“应用程序错误”。
我怀疑问题在于没有创建数据库表(当我查看heroku / psql上的统计信息时,表示表:0)。我不知道为什么。代码在github上 https://github.com/valentin-zambelli/kanban-for-students/tree/master
来自我的app.rb文件的快照
require 'sinatra'
require 'haml'
require 'data_mapper'
require "date"
require "pg"
class Note
include DataMapper::Resource
property :id, Serial
property :content, Text, :required => true
property :status, Integer
property :created_at, DateTime
property :updated_at, DateTime
end
configure do
DataMapper.setup(:default, ENV['postgres://coeastaxltnwlx:JnO2uo9HyracxQQ86n49u-FlzE@ec2-54-204-40-96.compute-1.amazonaws.com:5432/d7n7n4iggsqnke'] || "sqlite3://#{Dir.pwd}/development.db")
DataMapper.finalize.auto_upgrade!
end
并从gem文件中
source "https://rubygems.org"
ruby "2.1.2"
gem "sinatra"
gem "thin"
gem "haml"
gem 'data_mapper'
gem "pg"
gem "dm-postgres-adapter"
以下是我从$ heroku日志获取的最后几条错误消息
2014-10-27T10:55:48.591707+00:00 heroku[web.1]: Process exited with status 1
2014-10-27T10:55:48.600652+00:00 heroku[web.1]: State changed from starting to crashed
2014-10-27T10:55:55.697970+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=murmuring-waters-2400.herokuapp.com request_id=1a3e9d90-c9f2-4cdc-842b-55d3152089ba fwd="83.64.207.92" dyno= connect= service= status=503 bytes=
2014-10-27T10:55:56.508412+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=murmuring-waters-2400.herokuapp.com request_id=d83bdf15-c09c-4919-ab05-30b862199323 fwd="83.64.207.92" dyno= connect= service= status=503 bytes=
2014-10-27T10:56:06.872347+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=murmuring-waters-2400.herokuapp.com request_id=2e4a1984-c1ea-4234-8331-3f6a6f217137 fwd="54.161.222.26" dyno= connect= service= status=503 bytes=
非常感谢任何帮助!
答案 0 :(得分:0)
我认为问题出在DataMapper.setup
方法调用中。您正在查找ENV
对象(环境变量集合)中的数据库URL,这是好的,但您没有传递环境变量(DATABASE_URL
)的名称,而是将实际的URL复制到那里。你应该避免把它放在你的代码中。
尝试类似:
DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/development.db")