UPDATED: Sqlite3 gem rails not working on heroku and local env - ruby-on-rails

I am using heroku in a rails blog. After being able to fix the gem file following many related answers here, and being able to push my blog to heroku the app is not working locally.
I have change 'sqlite3' for 'pg' in my production env and add 'sqilte3' only in development test, push my changes to git and after to heroku. So far it was working but when I try to run the rails server, is asking me for 'sqlite3' again.
Error:
rb:177:in rescue in spec': Specified 'sqlite3' for database adapter, but the gem is not loaded. Addgem 'sqlite3'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError)
GEMFILE
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'
# 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'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'devise'
gem 'will_paginate', '~> 3.0.5'
gem 'cancancan'
gem "paperclip", "~> 5.0.0.beta1"
gem 'ratyrate'
# 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
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
gem "sqlite3"
gem 'rspec-rails', '~> 3.0'
end
group :development do
# 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
gem 'rails_12factor'
gem 'pg'
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
I have followed the steps here >> http://railscasts.com/episodes/342-migrating-to-postgresql?view=asciicast >> and is working now. Note for beginners, if you are going to use rails and heroku start you application with pg to save time debugging this.

I know it's a very old question but i got the same issue yesterday, am using Ubuntu 16.04 Rails 5.1.6.
I tried every solution that i found on the web but nothing worked for me, so am writing what solved this issue for me so it can help someone who get into this issue.
Simply check what version of Sqlite3 gem you are using:
bundle show sqlite3
for me it was sqlite3-1.4.0
Now just downgrade to a older version of the sqlite3 gem
Simply add gem 'sqlite3', '~> OLDER VERSION' in your gemfile replacing your current version of sqlite3
bundle install
That's it, it should work.

If you are using pg in production than... why sqlite3 confugration here
production:
<<: *default
database: db/production.sqlite3
update it from pg configuration.
Heroku is not compatible with sqlite3, you should use pg
Pg config.
development:
adapter: postgresql
encoding: unicode
database: blog_development
pool: 5
username: blog
password:

I would suggest removing the whole default section of your database.yml and just set everything for the rest:
development:
adapter: sqlite3
pool: 5
timeout: 5000
database: db/development.sqlite3
test:
adapter: sqlite3
pool: 5
timeout: 5000
database: db/test.sqlite3
production:
adapter: postgresql
encoding: unicode
database: <project name>
username: <%= ENV['USERNAME'] %>
password: <%= ENV['PASSWORD'] %>

Related

Rails server not starting, because of missing pg gem. Deinstalled postgres, but am getting the same error

I am getting the error when trying to start the Rails 5 server.
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).
I deleted local postgres via brew, removed also the existing mac app.
This is my Gemfile
source 'https://rubygems.org'
gem 'rails', '5.0.0'
gem 'puma', '3.4.0'
gem 'sass-rails', '5.0.6'
gem 'uglifier', '3.0.0'
gem 'coffee-rails', '4.2.1'
gem 'jquery-rails', '4.1.1'
gem 'turbolinks', '5.0.0'
gem 'jbuilder', '2.4.1'
group :development, :test do
gem 'sqlite3'
gem 'byebug', '9.0.0', platform: :mri
end
group :development do
gem 'web-console', '3.1.1'
gem 'listen', '3.0.8'
gem 'spring', '1.7.2'
gem 'spring-watcher-listen', '2.0.0'
end
group :production do
gem 'pg'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
I used
bundle install --without production
But I am still getting the same error. Can anyone help please?
Thanks,
Zin
It appears to me that you set up your application with the rails command and passed the option to utilize a postgres db. This will automatically stub out your database.yml file, and configure it for postgres. To be honest, I suggest you set up a database just like what you'd expect in prod. It's not that heavy and will save you headaches. (like this!)
While I don't think this is the best thing to reason about, personally, you might try configuring your rails app like this:
In your Gemfile:
group :development, :test do
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
end
group :production do
# Use postgresql as the database for Active Record
gem 'pg', '~> 0.18'
end
And then in your config/database.yml:
postgres: &postgres
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
sqlite: &sqlite
adapter: sqlite3
pool: 5
timeout: 5000
development:
<<: *sqlite
database: db/development.sqlite3
test:
<<: *sqlite
database: db/test.sqlite3
production:
<<: *postgres
database: postgresapp_production
username: postgresapp
password: <%= ENV['POSTGRESAPP_DATABASE_PASSWORD'] %>
This should hopefully work for you.
To explain, all I've done is basically taken the stubbed configuration from a sqlite rails app and pasted the default, development, and test configuration sections from the database.yml file into a postgres rails app's database.yml over top of the development and test sections. Then I changed all the "default"s in the sqlite configuration to "sqlite" and all the "default"s in the postgres section to "postgres". Then I added the sqlite gem to the development/test environments in the Gemile and moved the pg gem to production only.
You'd have to run the bundle command and the db:create task before you can run it.

ActiveRecord::ConnectionNotEstablished Ruby on Rails

I'm using mysql2 on Ruby on Rails, following Ruby on Rails 4 Essential Training by Kevin Skoglund, and I'm on the early chapters where it tells me to access the project by typing 'rails server' and opening 'localhost:3000' on my browser.
Problem is this:
Connection not Established
So I cannot access my project, and can't move on with the tutorials.
Also, I noticed something different between my and the tutorial's terminal. In my terminal, before booting WEBrick, it shows this:
/home/jmmaglinao16/.rvm/gems/ruby-2.3.0/gems/activesupport-4.0.0/lib/active_support/values/time_zone.rb:282: warning: circular argument reference - now
I'm not sure if it has any connection to the problem but that's what I have so far. Please help me guys. Thank you.
Gemfile:
source 'rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0'
# Use mysql as the database for Active Record
gem 'mysql2'
# Use SCSS for stylesheets
#gem 'sass-rails', '~> 4.0.0'
# Use Uglifier as compressor for JavaScript assets
#gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
#gem 'coffee-rails', '~> 4.0.0'
# See for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
#gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more:
#gem 'turbolinks'
# Build JSON APIs with ease. Read more:
#gem 'jbuilder', '~> 1.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
Database.yml:
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MYSQL driver
# gem install mysql2
#
# Ensure the MySQL gem is defined in your Gemfile
# gem 'mysql2'
#
# And be sure to use new-style password hashing:
#
development:
adapter: mysql2
encoding: utf8
database: #simple_cms_development
pool: 5
username: root
password: mypass
socket: /var/run/mysqld/mysqld.sock
# 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: mysql2
encoding: utf8
database: simple_cms_test
pool: 5
username: root
password: mypass
socket: /var/run/mysqld/mysqld.sock
production:
adapter: mysql2
encoding: utf8
database: simple_cms_production
pool: 5
username: root
password: mypass
socket: /var/run/mysqld/mysqld.sock
Try putting the '#' in the beginning of the line like here:
#database: simple_cms_development

Heroic Sqlite3 Error when Deploying [duplicate]

This question already has answers here:
Deploying RoR app to Heroku with SQLite 3 fails
(7 answers)
Closed 7 years ago.
I am continuously getting a
remote: An error occurred while installing sqlite3 (1.3.11), and Bundler cannot
remote: continue.
remote: Make sure that `gem install sqlite3 -v '1.3.11'` succeeds before bundling.
error when attempting to deploy to Heroku, I have tried all overflow questions thus far.
This is my gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.5.1'
# Use sqlite3 as the database for Active Record
gem 'pg'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
#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
gem 'therubyracer'
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# 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
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
end
group :development do
# 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
and this is my .yml
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: db/production.sqlite3
I'm thinking is has something to do with my .yml but I really have no idea. I can run it locally but when I true to
git push heroic master
I get that error
well the solution here is:
https://devcenter.heroku.com/articles/sqlite3
You need to use postgresql in production env. sqlite3 is not supported
so either change adapter to postgresql
or add your sqlite3 to develop and test group and add postgres to production group
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
and change your database.yml to:
# config/database.yml
default: &default
pool: 5
timeout: 5000
development:
<<: *default
adapter: sqlite3
database: db/development.sqlite3
test:
<<: *default
adapter: sqlite3
database: db/test.sqlite3
production:
<<: *default
adapter: postgresql
host: localhost
database: production
username: postgres
password: password
You cannot use SQLite3 on Heroku. Replace SQLIte3 with PostgreSQL, and update your Gemfile.
# replace gem "sqlite3" with
gem "pg"
You only need to update your development and test database configurations. As in production the database.yml file is updated automatically by Heroku. In fact, you don't even have to commit it to your repository.

Could not load 'active_record/connection_adapters/sqlite3_adapter'. Windows 7 local server

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.

fe_sendauth: no password supplied on localhost:300

I just installed heroku and then postgresql but now I am getting this error. Why do I need a password? what is my password?
I've spent at a couple of hours looking for something that works but can't get anything to work(I'm on windows):
this is my database.yml
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: postgresql
encoding: unicode
database: myapp_development
pool: 5
username: postgresql
password:
host: localhost
# 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: postgresql
encoding: unicode
database: myapp_test
pool: 5
username: postgresql
password:
host: localhost
production:
adapter: postgresql
encoding: unicode
database: myapp_production
pool: 5
username: postgresql
password:
host: localhost
This is my gemfile
source 'https://rubygems.org'
ruby '2.0.0'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'
gem 'devise'
gem 'pg'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
group :production do
gem 'rails_12factor'
end
# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.1.2'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
Any idea of what I can do?
On your local machine under the test and development sections of the database.yml file you should change the username to your logged in username. The rails generator makes it the same as your appname and that will not work. In production it does not matter as you deploy to heroku and that settings is automatically changed.
According to this page, you could use this command:
$ heroku config | grep HEROKU_POSTGRESQL
HEROKU_POSTGRESQL_RED_URL: postgres://user3123:passkja83kd8#ec2-117-21-174-214.compute-1.amazonaws.com:6212/db982398
The URL given is a postgresql connection string which contains the username and password embedded in it (user3123 and passkja83kd8 in this example).

Resources