I'm using the ActiveRecord class and was using "sqlite3" as the default. Then I wanted to deploy it on Heroku (which uses PostgreSQL). So I just added that in the Gemfile and installed the dependencies.
When I try to push to Heroku, it throws errors such as:
remote: Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
remote:
remote: /tmp/build_12cfde1548d0f1ff19f95340a86aab63/vendor/ruby-2.0.0/bin/ruby extconf.rb
remote: checking for sqlite3.h... no
remote: sqlite3.h is missing. Try 'port install sqlite3 +universal',
remote: 'yum install sqlite-devel' or 'apt-get install libsqlite3-dev'
remote: and check your shared library search path (the
remote: location where your sqlite3 shared library is located).
remote: *** extconf.rb failed ***
So then I tried removing the sqlite3 gem and I get this error from the application when I try to run it (I haven't tried deploying on Heroku yet):
Error:[rake --tasks] /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/connection_specification.rb:177:in `rescue in spec': Specified 'sqlite3' for database adapter, but the gem is not loaded. Add `gem 'sqlite3'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError)
from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/connection_adapters/connection_specification.rb:174:in `spec'
from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/connection_handling.rb:50:in `establish_connection'
from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/railtie.rb:120:in `block (2 levels) in <class:Railtie>'
from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.4/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.4/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.4/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.4/lib/active_support/lazy_load_hooks.rb:44:in `each'
from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activesupport-4.2.4/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/base.rb:315:in `<module:ActiveRecord>'
from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/activerecord-4.2.4/lib/active_record/base.rb:26:in `<top (required)>'
from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.4.0/lib/spring/application.rb:319:in `active_record_configured?'
from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.4.0/lib/spring/application.rb:251:in `disconnect_database'
from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.4.0/lib/spring/application.rb:97:in `preload'
from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.4.0/lib/spring/application.rb:143:in `serve'
from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.4.0/lib/spring/application.rb:131:in `block in run'
from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.4.0/lib/spring/application.rb:125:in `loop'
from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.4.0/lib/spring/application.rb:125:in `run'
from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/spring-1.4.0/lib/spring/application/boot.rb:18:in `<top (required)>'
from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /Users/adeesh/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from -e:1:in `<main>'
I have run out of ideas and am very new to ruby or rails for that matter. Any help is appreciated!
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.4'
# Use SCSS for stylesheets
gem 'sass-rails', ' 5.0.2'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails' , '>= 4.0.3'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks', '2.3.0'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '2.2.3'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', ' 0.4.0', group: :doc
# Use ActiveModel has_secure_password
gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Use sqlite3 as the database for Active Record
#gem 'sqlite3'
#gem 'activerecord'
gem 'pg'
gem 'rails_12factor', '>= 0.0.2'
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', '>= 3.4.0'
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
end
group :production do
#This is for use with Heroku
gem 'pg'
gem 'rails_12factor', '>= 0.0.2'
end
And here's a look at my database.ml file:
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: db/production.sqlite3
Update 2:
I'm getting this error if I try to run the development (localhost) db on the web page:
When I add it to the development and test group, I still get these errors:
remote:
remote: Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
remote:
remote: /tmp/build_23334fae90f17ca215e6f12340967cbd/vendor/ruby-2.0.0/bin/ruby extconf.rb
remote: checking for sqlite3.h... no
remote: sqlite3.h is missing. Try 'port install sqlite3 +universal',
remote: 'yum install sqlite-devel' or 'apt-get install libsqlite3-dev'
remote: and check your shared library search path (the
remote: location where your sqlite3 shared library is located).
remote: *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
remote: libraries and/or headers. Check the mkmf.log file for more details. You may
remote: need configuration options.
remote:
remote: Provided configuration options:
remote: --with-opt-dir
remote: --without-opt-dir
remote: --with-opt-include
remote: --without-opt-include=${opt-dir}/include
remote: --with-opt-lib
remote: --without-opt-lib=${opt-dir}/lib
remote: --with-make-prog
remote: --without-make-prog
remote: --srcdir=.
remote: --curdir
remote: --ruby=/tmp/build_23334fae90f17ca215e6f12340967cbd/vendor/ruby-2.0.0/bin/ruby
remote: --with-sqlite3-dir
remote: --without-sqlite3-dir
remote: --with-sqlite3-include
remote: --without-sqlite3-include=${sqlite3-dir}/include
remote: --with-sqlite3-lib
remote: --without-sqlite3-lib=${sqlite3-dir}/
remote:
remote:
remote: Gem files will remain installed in /tmp/build_23334fae90f17ca215e6f12340967cbd/vendor/bundle/ruby/2.0.0/gems/sqlite3-1.3.10 for inspection.
remote: Results logged to /tmp/build_23334fae90f17ca215e6f12340967cbd/vendor/bundle/ruby/2.0.0/gems/sqlite3-1.3.10/ext/sqlite3/gem_make.out
remote: An error occurred while installing sqlite3 (1.3.10), and Bundler cannot
remote: continue.
remote: Make sure that `gem install sqlite3 -v '1.3.10'` succeeds before bundling.
remote: !
remote: ! Failed to install gems via Bundler.
remote: !
remote: ! Detected sqlite3 gem which is not supported on Heroku.