3

My app is crashing every time I try to get it on Heroku (required for a school project). It works perfectly locally.

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.

Here is what the logs say:

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=

My Gemfile looks like this

    # 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

main.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
...

student.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
...

when I type heroku run console

require './main'

I get:

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>'

Any suggestions on what I can do?

Ken Bigler
  • 587
  • 1
  • 4
  • 15
  • 1
    What does your connection URL for datamapper look like? It looks like you have a sqlite connection string (which would cause datamapper to try and load the sqlite adapter). – matt May 24 '15 at 01:40
  • DataMapper::setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/development.db") – Ken Bigler May 24 '15 at 02:00
  • Have you set the `DATABASE_URL` env variable on Heroku? If it’s not set then `ENV['DATABASE_URL'`]` will be nil and Datamapper will try and use the Sqlite URL. – matt May 24 '15 at 02:25
  • Have a look at https://devcenter.heroku.com/articles/heroku-postgresql – matt May 24 '15 at 02:45
  • heroku config === mysterious-woodland-2551 Config Vars DATABASE_URL: postgres://qmhsuyvkmllaom:4cQVZFTs2e1G_px4nhhaJCQiuR@ec2-54-83-0-61.compute-1.amazonaws.com:5432/d9sr0qvmm6vlo LANG: en_US.UTF-8 but I still cannot get it to work – Ken Bigler May 24 '15 at 03:15
  • With that config it should work ok. The only thing I can think of is you need to restart your app, but according to [the docs](https://devcenter.heroku.com/articles/dynos#restarting) that should happen when you change your config vars anyway. – matt May 24 '15 at 16:04

1 Answers1

1

you are getting this error because heroku doesn't have Sqlite adapter it uses postgresql. So you will need to skip the use of Sqlite adapter on Heroku.

  1. if you are using DataMapper then use it like below-

DataMapper::setup(:default, ENV['DATABASE_URL'] || "sqlite3:your database file name")

  1. check if you are following below steps or not. May be you could have done few steps from below so ignore those and follow the rest.

1. Sign up at Heroku website:

https://id.heroku.com/login (Links to an external site.)

  1. Download toolbelt

  2. get bundler gem:

    gem install bundler

  3. create "Gemfile" in application directory:

  4. It will create "Gemfile.lock" file in your application directory.

bundle install --without production

  1. create "config.ru" file for rackup program with below contains

require './main'

run Sinatra::Application

  1. initialize git repository, in your application folder, run:

git init

  1. set git identity:

git config user.name "your-name"

git config user.email "yourname@email.com"

  1. add application to git repository and commit, in your application folder, run:

git add .

git commit -m "my first version"

  1. create application on Heroku

heroku create myapplication1

  1. push application from git repository to Heroku server

git push heroku master

12. create database on Heroku server

heroku run console

irb> require './main'

irb> DataMapper.auto_migrate!

connect to new web site

heroku open

Community
  • 1
  • 1
Neha Narlawar
  • 229
  • 3
  • 13
  • maybe the root of my error is in the line you mention, I am using: DataMapper::setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/development.db") – Ken Bigler May 24 '15 at 02:00
  • do install your bundles without production option. for more derails refer step number #5 – Neha Narlawar May 24 '15 at 02:02
  • yep that ENV ['database_url'] is very imp. – Neha Narlawar May 24 '15 at 02:04
  • I get LoadError: cannot load such file -- dm-sqlite-adapter when I do the heroku run console then require'./main' – Ken Bigler May 24 '15 at 02:15
  • what is your main file name where u have implemented this data_mapper? is it a ruby file? main will be your file name where you have implemented datamapper. – Neha Narlawar May 24 '15 at 02:17
  • main.rb, the full error is 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.rb:230:in `setup' from /app/student.rb:5:in `' from /app/main.rb:6:in `require' from /app/main.rb:6:in `' from (irb):1:in `require' from (irb):1 from /app/bin/irb:16:in `
    '
    – Ken Bigler May 24 '15 at 02:18
  • you made small mistake in your main.rb. your second ruby file is students.rb and your import statement in main.rb is "./student" so this is wrong. Change required statement in main.rb from "require './student'" to "require './students'" – Neha Narlawar May 24 '15 at 02:28
  • push all your latest changes to heroku again and recheck if that works. – Neha Narlawar May 24 '15 at 02:33
  • Ya, I still get the same issue, I elaborated in the above problem section – Ken Bigler May 24 '15 at 02:38
  • As Matt suggested can you please check the env variable run "heroku config" command and check the value of DATABASE_URL output should look like below ------ DATABASE_URL: postgres://faaugddxbqrjkq:UtsCRXiOeGKxLTXf0u6EVlr8Ql@ec2-23-23-126 -39.compute-1.amazonaws.com:5432/d9c14spkohg3mq LANG: en_US.UTF-8 RACK_ENV: production – Neha Narlawar May 24 '15 at 02:47
  • heroku config === mysterious-woodland-2551 Config Vars DATABASE_URL: postgres://qmhsuyvkmllaom:4cQVZFTs2e1G_px4nhhaJCQiuR@ec2-54-83-0-61.compute-1.amazonaws.com:5432/d9sr0qvmm6vlo LANG: en_US.UTF-8 but I still get the above errors – Ken Bigler May 24 '15 at 03:00