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.
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.
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'
Related
I have a Ruby on Rails app I've created. It uses Rails for the backend and frontend.
I want to deploy it to Heroku, so I've been following some steps to convert my SQLite database to PostgreSQL.
I got to the point where I need to remove SQLite code from my config/database.yml file and replace it with PostgreSQL specific code.
I've added different versions of PostgreSQL code I've found on tutorials into that file. However, once I have the new code in the file and then run rails db:create I get the below error:
rails aborted!
NameError: Cannot load database configuration:
undefined local variable or method `“RAILS_MAX_THREADS”' for main:Object
(erb):10:in `<main>'
Not sure what to do here. Searched the error and there was like one result for this error which had a solution that didn't work.
Another thing to note is that I recently ran bundle install after adding "pg" to the gemfile, installing PostgreSQL, and deleting gemfile.lock.
My database.yml file:
default: &default
adapter: postgresql
pool: <%= ENV.fetch(“RAILS_MAX_THREADS”) { 5 } %>
timeout: 5000
development:
<<: *default
database: development_nail_the_trail
test:
<<: *default
database: test_nail_the_trail
production:
<<: *default
database: production_nail_the_trail
My gemfile:
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby "2.6.1"
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem "rails", "~> 6.0.3", ">= 6.0.3.4"
# Use sqlite3 as the database for Active Record
gem "pg"
# Use Puma as the app server
gem "puma", "~> 4.1"
# Use SCSS for stylesheets
gem "sass-rails", ">= 6"
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem "webpacker", "~> 4.0"
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem "turbolinks", "~> 5"
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem "jbuilder", "~> 2.7"
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
# Reduces boot times through caching; required in config/boot.rb
gem "bootsnap", ">= 1.4.2", require: false
gem "bcrypt", "~> 3.1.7"
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem "byebug", platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem "web-console", ">= 3.3.0"
gem "listen", "~> 3.2"
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem "spring"
gem "spring-watcher-listen", "~> 2.0.0"
gem "pry", "~> 0.13.1"
gem "pry-rails"
gem "faker"
gem "omniauth", "~> 2.0.4"
gem "omniauth-facebook"
gem "omniauth-rails_csrf_protection", "~> 1.0"
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem "capybara", ">= 2.15"
gem "selenium-webdriver"
# Easy installation and use of web drivers to run system tests with browsers
gem "webdrivers"
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby]
You have the wrong kind of quote characters here
ENV.fetch(“RAILS_MAX_THREADS”)
It should be
ENV.fetch("RAILS_MAX_THREADS")
I deleted postgres from my machine by
brew rm postgresql --force
rm -rf /usr/local/var/postgres
I created a new rails app. This is my standard gemfile
source 'https://rubygems.org'
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
gem 'sqlite3'
gem 'puma', '~> 3.0'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.2'
gem 'jquery-rails'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.5'
group :development, :test do
gem 'byebug', platform: :mri
end
group :development do
gem 'web-console'
gem 'listen', '~> 3.0.5'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
Then
bundle install
rails s
Although I haven't specified any pg gem in my gemfile I am getting the error when trying to get to localhost
> Specified 'postgresql' for database adapter, but the gem is not loaded.
> Add `gem 'pg'` to your Gemfile
> (and ensure its version is at the minimum required by ActiveRecord).
> Extracted source (around line #176):
require path_to_adapter
rescue Gem::LoadError => eraise Gem::LoadError,
"Specified '#{spec[:adapter]}' for database adapter,
but the gem is not loaded.
Add `gem '#{e.name}'` to your Gemfile
(and ensure its version is at the minimum required by ActiveRecord)."
rescue LoadError => eraise LoadError,
"Could not load '#{path_to_adapter}'.
Make sure that the adapter in config/database.yml is valid.
If you use an adapter other than 'mysql2', 'postgresql' or 'sqlite3'
add the necessary adapter gem to the Gemfile.", e.backtrace
end
This is my database.yml file which doesn'r include any postgres either.
# 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
What's the problem here? Before I was using sqlite in dev and test, and pg in production. There still seem to be some references in the system which I obviously couldn't get rid of.
I have the same problem.
Write in your console:
echo $DATABASE_URL
IF RESULT IS:
postgresql://user:password#localhost/database
Look for in your .bash_profile or .profile
export DATABASE_URL="postgresql://user:password#localhost/database"
Comment this line and to be happy.
Read here
http://edgeguides.rubyonrails.org/configuring.html
Section 3.5
"When duplicate connection information is provided the environment variable (DATABASE_URL) will take precedence"
You still have postgres listed as your adaptor in your database.yml file. Once you change your database.yml to reflect the fact that you are not using postgres you will need to run rake db:drop db:create db:migrate
I have been going through the Rails tutorial, https://www.railstutorial.org/book/static_pages, and the first two chapters went fine. I installed Rails on my Laptop made a hello world app and a toy with the scaffold generator. There were some things I had to do differently because I am doing everything locally instead of on a cloud environment and because I am using Windows 7, but I got everything to work.
When I tried running a local server and going to my http://localhost:3000/static_pages/home page, i got the error in the Title. The following is the full error message:
Could not load 'active_record/connection_adapters/sqlite3_adapter'. Make sure that the adapter in config/database.yml is valid. If you use an adapter other than 'mysql', 'mysql2', 'postgresql' or 'sqlite3' add the necessary adapter gem to the Gemfile.
I figure it must be something with the Gemfile because that was the only difference between this and my other apps, I'm just not sure what to change. I included the Gemfile and the database.yml. Thanks in advance.
#Gemfile - sample_app
source 'https://rubygems.org'
gem 'rails', '4.2.2'
gem 'bcrypt-ruby', :require => 'bcrypt'
gem 'faker', '1.4.2'
gem 'carrierwave', '0.10.0'
gem 'mini_magick', '3.8.0'
gem 'fog', '1.23.0'
gem 'will_paginate', '3.0.7'
gem 'bootstrap-will_paginate', '0.0.10'
gem 'bootstrap-sass', '3.2.0.0'
gem 'sass-rails', '5.0.2'
gem 'uglifier', '2.5.3'
gem 'coffee-rails', '4.1.0'
gem 'jquery-rails', '4.0.3'
gem 'turbolinks', '2.3.0'
gem 'jbuilder', '2.2.3'
gem 'sdoc', '0.4.0', group: :doc
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
gem 'sqlite3'
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
group :test do
gem 'minitest-reporters', '1.0.5'
gem 'mini_backtrace', '0.1.3'
gem 'guard-minitest', '2.3.1'
end
group :production do
gem 'pg', '0.17.1'
gem 'rails_12factor', '0.0.2'
gem 'puma', '2.11.1'
end
Database.yml
# 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
In your Gemfile, you specify sqlite3 (the 'sqlite3' gem) for development and testing, and postgres (the 'pg' gem) for production.
But in your database.yml, you've specified the production database as sqlite3:
<database.yml>
...
production:
<<: *default
database: db/production.sqlite3
which will try to use the default adapter (sqlite3) and will look for a database file with .sqlite3 as the file extension.
You need to change your database.yml so that it uses a postgres database:
production:
adapter: postgresql
encoding: unicode
pool: 5
database: db/production
(Make sure you have postgres running on your machine either as an app or as a service.)
Or you can change your Gemfile so that you use SQLite3 for production, too.
If you tried to run the production version on your Windows machine but perhaps were running a development or test version on your OSX machine, this could be the problem.
My Gemfile looks like this:
source 'https://rubygems.org'
gem 'rails', '4.0.2'
gem 'bootstrap-sass', '2.1.0.0'
gem 'activesupport', '4.0.2'
gem 'jquery-rails', '2.0.2'
gem 'railties', '4.0.2'
gem 'sass-rails', '4.0.1'
gem 'coffee-rails', '4.0.1'
gem 'rails_12factor'
gem 'actionpack', '4.0.2'
gem 'sqlite3', '1.3.5'
group :development, :test do
gem 'rspec-rails', '2.11.0'
gem 'guard-rspec', '1.2.1'
gem 'guard-spork', '1.2.0'
gem 'childprocess', '0.3.6'
gem 'spork', '0.9.2'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '4.0.1'
gem 'coffee-rails', '4.0.1'
gem 'uglifier', '1.2.3'
end
group :test do
gem 'capybara', '1.1.2'
gem 'factory_girl_rails', '4.1.0'
gem 'cucumber-rails', '1.2.1', :require => false
gem 'database_cleaner', '0.7.0'
# gem 'launchy', '2.1.0'
# gem 'rb-fsevent', '0.9.1', :require => false
# gem 'growl', '1.0.3'
end
group :production do
gem 'pg', '0.12.2'
end
I run bundle install and bundle update but when I visit my app locally I get this error:
Specified 'sqlite3' for database adapter, but the gem is not loaded.
Add gem 'sqlite3' to your Gemfile.
I tried bundle show sqlite3 and I get /Users/siaW/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/sqlite3-1.3.5 which means I do have the Gem right?
So why isn't it loading?
In my database.yml I have this:
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem '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
I think you may try this:
Go into your Gemfile.lock file and search for the 'sqlite3' entry. You'll note it reads sqlite3 (1.3.8-x86-mingw32). Change that to sqlite3 (1.3.8-x64-mingw32) and then run the bundle install command and everything should work like normal.
from Sqlite3 gem not loading, gem installed and specified in project
I had this on OSX for a spec/dummy app. Without rebuilding the gemset (just rebuilding sqlite3), it was unsuccessful.
I had to do the following to get everything built properly:
rvm gemset empty
brew update
brew install sqlite
bundle update
I'm new of rails, and i have this big problem. I'm running rails 3.2.9 and Ruby 1.9.3, I did a porting of a rails app from linux to windows, but in windows i'm having a lot of problems with mysql2 gem.
I installed mysql2 gem yesterday and than i tried to run rake db:migrate but i have this output:
rake aborted!
Please install the mysql2 adapter: gem install activerecord-mysql2-adapter (cannot load such file -- mysql2)
C:/Users/RoccaA/Desktop/project/config/environment.rb:5:in `'
Tasks: TOP => db:migrate => environment
(See full trace by running task with --trace)
Then this is my Gemfile
gem 'rails', '3.2.9'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
#gem 'sqlite3'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
# gem 'coffee-rails', '~> 3.2.1'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
# gem 'uglifier', '>= 1.0.3'
end
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
gem 'jquery-rails'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
# Use unicorn as the app server
# gem 'unicorn'
# Deploy with Capistrano
# gem 'capistrano'
# To use debugger
# gem 'debugger'
# this gems needs for auth
gem 'cancan'
gem 'devise'
gem 'rolify'
gem 'execjs'
gem 'therubyracer', :platform => :ruby
gem 'populator'
gem 'faker'
gem 'paperclip'
gem 'simple_xlsx_writer'
gem 'roo'
gem 'mysql2', '0.3.11'
gem 'simple_xlsx_writer'
gem 'rake', '~> 10.0.4'
gem 'icalendar'
And this is my database.yml
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: emc
pool: 5
username: root
password: root
socket: /var/run/mysqld/mysqld.sock
testing:
adapter: mysql2
encoding: utf8
reconnect: false
database: emc
pool: 5
username: root
password: root
socket: /var/run/mysqld/mysqld.sock
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: emc
pool: 5
username: root
password: root
socket: /var/run/mysqld/mysqld.sock
I tried to solve this problem in a lots of ways, i read that i have to use mysql2 version < 0.3 but with this version I have this output
WARNING: This version of mysql2 (0.2.18) isn't compatible with Rails 3.1 as the ActiveRecord adapter was pulled into Rails itself.
WARNING: Please use the 0.3.x (or greater) releases if you plan on using it in Rails >= 3.1.x
rake aborted!
undefined method `accept' for nil:NilClass
Tasks: TOP => db:migrate
(See full trace by running task with --trace)**
Hope someone can help me, thanks.
Try this to you gemfile
instead of using:
gem 'mysql2', '0.3.11'
use this:
gem 'mysql2'
This is working for me.
And by the way you have duplicate gem
gem 'simple_xlsx_writer'
Forget about it.Insted of it use rails installer from http://www.railsinstaller.org/ it will automatically install mysql2 with ruby and rails with latest versions
Installing Rails and the mysql2 gem in windows is not as easy as on other os. But i found a good answer to your question:
Unable to install MySQL2 gem on Windows 7
The best thing to do is, to install rails on windows with the rubyinstaller.
gem "mysql2", "~> 0.3.11"
and then bundle install
Good detailed steps here => http://blog.mmediasys.com/2011/07/07/installing-mysql-on-windows-7-x64-and-using-ruby-with-it/
Some key points are installing the right version of mysql, the dot net connector, and the gem. Also be sure to place the libmysql file in the correct place.