ActiveRecord::ConnectionNotEstablished Ruby on Rails - 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

Related

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

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'] %>

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.

PG::ConnectionBad: could not connect to server (heroku)

i can push to heroku just fine.. however when I run a rake i get this error:
PG::ConnectionBad: could not connect to server
I can run locally ok so not really sure why I am having trouble pushing to heroku - any help would be great
I suspect this is related to my database.yml file:
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: postgresql
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
Also here is my gemfile:
source 'http://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.8'
# Use sqlite3 as the database for Active Record
group :development do
gem 'sqlite3'
gem 'capistrano'
end
group :production do
gem 'pg'
gem 'mysql2'
gem 'activerecord-mysql-adapter'
gem 'rails_12factor'
end
# Use SCSS for stylesheets
gem 'coffee-rails'
gem 'bootstrap-sass', '~> 3.3.3'
gem 'sass-rails', '>= 3.2'
gem 'autoprefixer-rails'
gem 'will_paginate', '~> 3.0.7'
gem 'will_paginate-bootstrap'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
# 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', '~> 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
# Use debugger
# gem 'debugger', group: [:development, :test]
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin]
You should not commit database.yml into heroku:
When Rails applications are deployed to Heroku a database.yml file is
automatically generated for your application that configures
ActiveRecord to use a PostgreSQL connection and to connect to the
database located at DATABASE_URL. This behavior is only needed up to
Rails 4.1. Any later version contains direct support for specifying a
connection URL and configuration in the database.yml so we do not have
to overwrite it.
Read heroku documentation about this.

Rails on windows error: Could not load 'active_record/connection_adapters/sqlite3_adapter'

I had the exact problem as in this question. And I followed the steps as given in the accepted answers. It worked as expected. But unexpectedly I am getting this error on running the app:
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 am also attaching the screenshot.
My gemfile has the required dependencies(sqlite3):
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.6'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# 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', '~> 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
# Use debugger
# gem 'debugger', group: [:development, :test]
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin]
And also my database.yml has the needed adapter(sqlite3):
# 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
So what is wrong here?
My Ruby version is 4.1.6 and I have installed rails using gem install rails command. So it must be the latest one.
I changed ruby version to 2.0 and all of it worked! So it seems that ruby 2.1.0+ does not work properly with Rails on windows as of the time of writing this answer.

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