Home > Software design >  Sinatra LoadError: Error loading the 'sqlite3' Active Record adapter
Sinatra LoadError: Error loading the 'sqlite3' Active Record adapter

Time:11-13

Hello i'm trying to push a sinatra repo to dokku but every time come out this error

rake aborted! LoadError: Error loading the 'sqlite3' Active Record adapter. Missing a gem it depends on? sqlite3 is not part of the bundle. Add it to your Gemfile.

seems that this config on environment file is causing this issue

ActiveRecord::Base.establish_connection(
  adapter: "sqlite3",
  database: "db/#{ENV["SINATRA_ENV"]}.sqlite"
)

here is the file

ENV["SINATRA_ENV"] ||= "development"
require "bundler/setup"
Bundler.require(:default, ENV["SINATRA_ENV"])




require "rack-flash"
require "sinatra/json"
require "sprockets"
require "friendly_id"




ActiveRecord::Base.establish_connection(
  adapter: "sqlite3",
  database: "db/#{ENV["SINATRA_ENV"]}.sqlite"
)



  
# Load initializers
Dir["./config/initializers/**/*.rb"].each { |file| require file }

require_all "app"

I place the sqlite gem into development group

group :development do
  gem "letter_opener"
  gem "sqlite3"
 
end

I've tried already rails_12factor and therubyracer but the issue still so,someone know why this?

place into the gemfile

gem 'rails_12factor'
gem 'therubyracer'

database.yml

# SQLite. Versions 3.8.0 and up are supported.
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
#
default: &default
  adapter: sqlite3
  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
  adapter: postgresql
  encoding: unicode
  port: 5432
  database: postgres://postgres:xxxxxxxxxxx@dokku-postgres-yyyyyy-db:5432/yyyyy_db

LOG

   Caused by:
       Gem::LoadError: sqlite3 is not part of the bundle. Add it to your Gemfile.
       /tmp/build/vendor/bundle/ruby/2.7.0/gems/bundler-2.3.10/lib/bundler/rubygems_integration.rb:291:in `block (2 levels) in replace_gem'
       /tmp/build/vendor/bundle/ruby/2.7.0/gems/activerecord-7.0.4/lib/active_record/connection_adapters/sqlite3_adapter.rb:13:in `<top (required)>'

CodePudding user response:

just set the environment db on environment.rb

configure :development do
ActiveRecord::Base.establish_connection(
  adapter: "sqlite3",
  database: "db/#{ENV["SINATRA_ENV"]}.sqlite"
)
end
  • Related