2
votes

I'm new to Rails and was trying to launch my server. Running the command rails server generated an error

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

I looked at many of these previous questions and none seems to solve it. Here is my Gemfile code

if RUBY_VERSION =~ /1.9/
   Encoding.default_external = Encoding::UTF_8
   Encoding.default_internal = Encoding::UTF_8
end

source 'https://rubygems.org'

gem 'rails', '~> 4.2.0'

gem 'ey_config'
gem 'rails_autolink'
gem 'simple_form'

# Assets
gem 'jquery-rails'
gem 'sass-rails'
gem 'coffee-rails'
gem 'uglifier'

platform :ruby do
   gem 'mysql2'
   gem 'pg'
   gem 'activerecord-postgis-adapter', '3.0.0.beta2'
   gem 'sqlite3'

   gem 'newrelic_rpm'
   gem 'unicorn'
   gem 'puma'
   gem 'json'
   gem 'minitest'
   gem 'psych'
   gem 'racc'
end

platforms :jruby do
   ar_jdbc_version = '~> 1.3'
   gem 'activerecord-jdbc-adapter', ar_jdbc_version
   gem 'activerecord-jdbcmysql-adapter', ar_jdbc_version
   gem 'activerecord-jdbcpostgresql-adapter', ar_jdbc_version
   gem 'activerecord-jdbcsqlite3-adapter', ar_jdbc_version
   gem 'jdbc-mysql', :require => false
   gem 'jdbc-sqlite3', :require => false
   gem 'jdbc-postgres', :require => false

   gem 'jruby-openssl'
   gem 'trinidad'
end

platform :rbx do
   gem 'rubysl'
   gem 'rubysl-test-unit', :require => false
end

# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
group :development, :test do
   gem 'tzinfo-data'
end

And here is my database.yml file

# SQLite version 3.x
#   gem install sqlite3
development:
   adapter: sqlite3
   database: db/development.sqlite3
   pool: 5
   timeout: 5000

# 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:
   adapter: sqlite3
   database: db/test.sqlite3
   pool: 5
   timeout: 5000

production:
   adapter: sqlite3
   database: db/production.sqlite3
   pool: 5
   timeout: 5000`

Here is the code in my rakefile:

# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)
require 'rake'

Listr::Application.load_tasks

task :travis => ['db:create:all', 'db:migrate', :default]

It will be also appreciated for providing any explanation accompanying the answer. Thanks.

2

2 Answers

3
votes

Your sqlite3 gem is not being loaded in production, because of the version mismatch. so, update you gemfile as gem 'sqlite3', '~> 1.3.13' it'll work. Keep it under group :production, :test It'll be good when you push your code to heroku.

1
votes

Your sqlite3 gem is not being loaded, because of where you've got it in the Gemfile. Take it out of platform :ruby do and place it outside of that block , May be right under gem 'rails', '~> 4.2.0'