每次我尝试在 Heroku 上获取它时,我的应用程序都会崩溃(学校项目需要)。它在本地完美运行。
An error occurred in the application and your page could not be served. Please try again in a few moments.
If you are the application owner, check your logs for details.
日志是这样说的:
2015-05-23T23:52:47.952635+00:00 heroku[web.1]: State changed from crashed to starting
2015-05-23T23:52:50.499347+00:00 heroku[web.1]: Starting process with command `bundle exec thin start -R config.ru -e $RACK_ENV -p 10414`
2015-05-23T23:52:52.736994+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/dm-core-1.2.1/lib/dm-core/adapters.rb:163:in `require': cannot load such file -- dm-sqlite-adapter (LoadError)
...
2015-05-23T23:53:11.790209+00:00 heroku[run.9012]: Awaiting client
2015-05-23T23:53:11.844408+00:00 heroku[run.9012]: Starting process with command `bundle exec irb`
2015-05-23T23:53:12.025719+00:00 heroku[run.9012]: State changed from starting to up
2015-05-23T23:54:03.317467+00:00 heroku[run.9012]: Process exited with status 0
2015-05-23T23:54:03.336441+00:00 heroku[run.9012]: State changed from up to complete
2015-05-23T23:54:08.767294+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=mysterious-woodland-2551.herokuapp.com request_id=a53bb16e-88e6-4701-857f-bd3319ce8d91 fwd="129.210.115.16" dyno= connect= service= status=503 bytes=
2015-05-23T23:54:09.427490+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=mysterious-woodland-2551.herokuapp.com request_id=8effbba8-b14f-4b8a-bb2f-a7a4eae5e44c fwd="129.210.115.16" dyno= connect= service= status=503 bytes=
我的 Gemfile 看起来像这样
# A sample Gemfile
source "https://rubygems.org"
ruby '2.0.0'
gem 'sinatra'
gem 'slim'
gem 'sass'
gem 'dm-core'
gem 'dm-migrations'
gem 'thin'
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
主要.rb
#!/user/bin/env ruby
require 'sinatra'
require 'slim'
require 'sass'
require './student'
configure do
enable :sessions
set :username, 'kenneth'
set :password, 'bigler'
end
get('/styles.css'){ scss :styles }
get '/' do
slim :home
end
...
学生.rb
require 'dm-core'
require 'dm-migrations'
# DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/development.db")
DataMapper::setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/development.db")
class Student
include DataMapper::Resource
property :id, Serial
property :first_name, Text
property :last_name, Text
property :year, Integer
end
configure do
enable :sessions
set :username, 'kenneth'
set :password, 'bigler'
end
DataMapper.finalize
get '/students' do
...
当我输入 heroku run console 时
需要'./main'
我得到:
LoadError: cannot load such file -- dm-sqlite-adapter
from /app/vendor/bundle/ruby/2.0.0/gems/dm-core-1.2.1/lib/dm-core/adapters.rb:163:in `require'
from /app/vendor/bundle/ruby/2.0.0/gems/dm-core-1.2.1/lib/dm-core/adapters.rb:163:in `load_adapter'
from /app/vendor/bundle/ruby/2.0.0/gems/dm-core-1.2.1/lib/dm-core/adapters.rb:133:in `adapter_class'
from /app/vendor/bundle/ruby/2.0.0/gems/dm-core-1.2.1/lib/dm-core/adapters.rb:13:in `new'
from /app/vendor/bundle/ruby/2.0.0/gems/dm-core-1.2.1/lib/dm-core.rb:230:in `setup'
from /app/student.rb:5:in `<top (required)>'
from /app/main.rb:6:in `require'
from /app/main.rb:6:in `<top (required)>'
from (irb):1:in `require'
from (irb):1
from /app/bin/irb:16:in `<main>'
对我能做什么有什么建议吗?
最佳答案
你收到这个错误是因为 heroku 没有它使用 postgresql 的 Sqlite 适配器。因此,您需要跳过在 Heroku 上使用 Sqlite 适配器。
- 如果您正在使用 DataMapper,那么请像下面这样使用它-
DataMapper::setup(:default, ENV['DATABASE_URL'] || "sqlite3:你的数据库文件名")
- 检查您是否按照以下步骤操作。也许您可以从下面完成几步,所以请忽略这些并按照其余步骤进行操作。
<强>1。在 Heroku 网站注册:
https://id.heroku.com/login (链接到外部站点。)
下载工具带
获取 bundler gem:
gem install bundler
在应用程序目录中创建“Gemfile”:
它将在您的应用程序目录中创建“Gemfile.lock”文件。
bundle install --without production
- 为 rackup 程序创建“config.ru”文件,包含以下内容
需要'./main'
运行 Sinatra::应用程序
- 初始化 git 仓库,在你的应用程序文件夹中,运行:
git init
- 设置 git 身份:
git config user.name "your-name"
git config user.email "yourname@email.com"
- 将应用程序添加到 git 存储库并提交,在您的应用程序文件夹中,运行:
git add .
git commit -m "my first version"
- 在 Heroku 上创建应用程序
heroku create myapplication1
- 将应用程序从 git 存储库推送到 Heroku 服务器
git push heroku master
<强>12。在 Heroku 服务器上创建数据库
heroku run console
irb> 需要 './main'
irb> DataMapper.auto_migrate!
connect to new web site
heroku open
关于heroku - sqlite3 和 heroku 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30418789/